部員(海産)が課せられてる○×ゲーム、ではなくクラシックな○×ゲームを部長は実装しました。
正直今さら感はありますが(しかもバグがありちゃんとした勝利判定になってない)
もしも暇な部員が居たら直してくれるでしょう…多分(まあ難読化されていて、さらにネットの強い人のコード丸パクりだから無理かも知れないけど)
部長は動作を理解してるのかって?してる訳ないじゃん
from random import *
def init():
print("-------")
print("| | | |")
print("-------")
print("| | | |")
print("-------")
print("| | | |")
print("-------")
player = randint(1,2) #1で○2で×
print("あなたは○、先行です" if player == 1 else "あなたは×、後攻です")
return player == 1
def null(map):
return not ([] == list(filter(lambda x: True if x == 0 else False, map)))
def check(map, mark):
def subcheck(x, null):
if x and mark and (not null):
print("You win!" if mark else "You lose")
exit()
elif x and (not mark) and (not null):
print("You win!" if mark else "You lose")
exit()
for x in range(0,9,3): #横一列の勝利判定
subcheck(map[x+0] == map[x+1] == map[x+2], 0 == map[x+0] + map[x+1] + map[x+2])
for y in range(0,3): #縦一列の勝利判定
subcheck(map[y+0] == map[y+3] == map[y+6], 0 == map[y+0] + map[y+3] + map[y+6])
subcheck(map[0] == map[4] == map[8], 0 == map[0] + map[4] + map[8])
subcheck(map[2] == map[4] == map[6], 0 == map[2] + map[4] + map[6])
def update(x, mark, map): #引数はマス選択
# print(mark)
print(map)
print(map[x])
map[x] = 1 if mark else 2
print("-------\n|", end="")
for x in range(0,9):
print( "○" if map[x] == 1 else "×" if map[x] == 2 else " ", end="|")
if (x+1)%3 == 0: print("\n-------\n|", end="") if not (x+1 == 9) else print("\n-------\n")
def enemy_ai草ww(map, mark):
map_copy = list(map)
enemy_map = []
for x in range(0,len(map)):
if map_copy.pop(0) == 0:
enemy_map.insert(0, x)
print(enemy_map)
return enemy_map
def main():
map = [0, 0, 0, 0, 0, 0, 0, 0, 0]
# enemy_map = []
# map = [0, 1, 1, , 0, 0, 0, 0, 0]
mark = init()
turn = True
# update(int(input("あなたの番です。マスを選んでください: ")), mark, map)
while null(map):
if mark == turn:
def test_input():
user_input = int(input("あなたの番です。マスを選んでください: "))
if (map[user_input] == 0 or map[user_input] == mark):
update(user_input, mark, map)
return
else:
test_input()
test_input()
check(map,mark)
else:
a = int(choice(enemy_ai草ww(map, mark)))
print(a)
update(a, not mark, map)
check(map,mark)
print(map)
# check(map, mark)
turn = not turn
print("draw")
main()