うまく行ってないのかもしれませんが、Deep Learningを使ってオセロを動かしてみました。GitHubにおいてリポジトリを公開中です。
よかった。本も買っていたし。
また一つ夢が達成できた。
2017年12月26日火曜日
2017年12月24日日曜日
数当て 対戦
import random
if __name__ == '__main__':
s = random.randint(0,99)
for x in range(10):
s2 = int(input('>>'))
s1 = random.randint(0,99)
print(s1)
i = abs(s - s1)
j = abs(s - s2)
if i * j == 0:
break
if i == j:
print('even')
elif i > j:
print('advantage')
elif i < j:
print('behind')
if (i < 5)or(j < 5):
print('near!')
if i == j:
print('draw')
elif i == 0:
print('you lose.')
elif j == 0:
print('you win.')
else:
print(s)
if __name__ == '__main__':
s = random.randint(0,99)
for x in range(10):
s2 = int(input('>>'))
s1 = random.randint(0,99)
print(s1)
i = abs(s - s1)
j = abs(s - s2)
if i * j == 0:
break
if i == j:
print('even')
elif i > j:
print('advantage')
elif i < j:
print('behind')
if (i < 5)or(j < 5):
print('near!')
if i == j:
print('draw')
elif i == 0:
print('you lose.')
elif j == 0:
print('you win.')
else:
print(s)
2017年12月23日土曜日
ascii
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
var
c, d: Char;
i, j: integer;
s: string;
begin
try
{ TODO -oUser -cConsole メイン : ここにコードを記述してください }
Randomize;
c:=Chr(Ord('a')+Random(20));
j:=Random(Ord('z')-Ord(c))+1;
d:=c;
for i := 1 to j do
d := Succ(d);
for i := 1 to 8 do
begin
Writeln(' '+c+' => '+j.ToString);
Readln(s);
if s = d then
begin
Writeln('clear');
break;
end;
end;
Writeln(d);
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
var
c, d: Char;
i, j: integer;
s: string;
begin
try
{ TODO -oUser -cConsole メイン : ここにコードを記述してください }
Randomize;
c:=Chr(Ord('a')+Random(20));
j:=Random(Ord('z')-Ord(c))+1;
d:=c;
for i := 1 to j do
d := Succ(d);
for i := 1 to 8 do
begin
Writeln(' '+c+' => '+j.ToString);
Readln(s);
if s = d then
begin
Writeln('clear');
break;
end;
end;
Writeln(d);
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
数字あて
import random
if __name__ == '__main__':
s = random.randint(0,99)
while True:
t = int(input('>>'))
if s == t:
print('clear')
break
elif s > t:
print('more')
elif s < t:
print('less')
if __name__ == '__main__':
s = random.randint(0,99)
while True:
t = int(input('>>'))
if s == t:
print('clear')
break
elif s > t:
print('more')
elif s < t:
print('less')
2017年12月22日金曜日
number strike
import random
if __name__ == '__main__':
s = ''
t = [str(x) for x in range(9)]
for x in range(4):
i = random.randint(0,len(t))
s += t[i]
del t[i]
while True:
t = input('>>')
if t == '0000':
print(s)
elif s == t:
print('clear!')
break
else:
i = 0
j = 0
for x in range(len(s)):
if t[x] in s:
if t[x] == s[x]:
i += 1
else:
j += 1
print('{0},{1}'.format(i,j))
if __name__ == '__main__':
s = ''
t = [str(x) for x in range(9)]
for x in range(4):
i = random.randint(0,len(t))
s += t[i]
del t[i]
while True:
t = input('>>')
if t == '0000':
print(s)
elif s == t:
print('clear!')
break
else:
i = 0
j = 0
for x in range(len(s)):
if t[x] in s:
if t[x] == s[x]:
i += 1
else:
j += 1
print('{0},{1}'.format(i,j))
ox game i made.
import random
class Num():
pass
def draw():
s = ''
for x in range(9):
s += numbers[x].num
if (x+1) % 3 == 0:
s += '\n'
print('====')
print(s[0:-1])
def key():
if i % 2 == 0:
while True:
s = input('>>')
if temp(s) == True:
numbers[int(s)-1].num = 'o'
break
else:
for x in range(50):
s = random.randint(0,8)
if temp(str(s+1)) == True:
numbers[s].num = 'x'
break
def temp(count):
for x in numbers:
if x.num == count:
return True
return False
def check():
def part(arg):
s = numbers[arg[0]].num
for x in arg:
if numbers[x].num != s:
return ''
return s
s = ''
s += part([0,1,2])
s += part([3,4,5])
s += part([6,7,8])
s += part([0,4,8])
s += part([6,4,2])
s += part([0,3,6])
s += part([1,4,7])
s += part([2,5,8])
if s == '':
return ''
else:
return s[0]
if __name__ == '__main__':
numbers = [Num() for x in range(9)]
l = [0 for x in range(9)]
i = 1
for x in numbers:
x.num = str(i)
i += 1
draw()
for i in range(9):
key()
draw()
s = check()
if s == 'o':
print('you win!')
break
elif s == 'x':
print('you lose.')
break
else:
if s == '':
print('drow')
class Num():
pass
def draw():
s = ''
for x in range(9):
s += numbers[x].num
if (x+1) % 3 == 0:
s += '\n'
print('====')
print(s[0:-1])
def key():
if i % 2 == 0:
while True:
s = input('>>')
if temp(s) == True:
numbers[int(s)-1].num = 'o'
break
else:
for x in range(50):
s = random.randint(0,8)
if temp(str(s+1)) == True:
numbers[s].num = 'x'
break
def temp(count):
for x in numbers:
if x.num == count:
return True
return False
def check():
def part(arg):
s = numbers[arg[0]].num
for x in arg:
if numbers[x].num != s:
return ''
return s
s = ''
s += part([0,1,2])
s += part([3,4,5])
s += part([6,7,8])
s += part([0,4,8])
s += part([6,4,2])
s += part([0,3,6])
s += part([1,4,7])
s += part([2,5,8])
if s == '':
return ''
else:
return s[0]
if __name__ == '__main__':
numbers = [Num() for x in range(9)]
l = [0 for x in range(9)]
i = 1
for x in numbers:
x.num = str(i)
i += 1
draw()
for i in range(9):
key()
draw()
s = check()
if s == 'o':
print('you win!')
break
elif s == 'x':
print('you lose.')
break
else:
if s == '':
print('drow')
登録:
投稿 (Atom)