import random import gameboard as gb import gamejudge as gj import gamerenderer from gameconstants import Cells from gamejudge import Turn from gamejudge import Direction ## demo gameboard = gb.GameBoard() gamejudge = gj.GameJudge( gameboard ) ## share gameboard with GameJudge instance userchip = Cells.UNKNOWN userturn = Turn.NOT_YET cpuchip = Cells.UNKNOWN cputurn = Turn.NOT_YET gamerenderer.display_gameboard( gameboard.get_gameboard() ) while 1==1 : direction = gamejudge.get_instruction() ## ゲーム終了 if direction == Direction.GAMEOVER : break ## ユーザの先手後選択と駒の選択 elif direction == Direction.USER_INPUT_TURN_ORDER : userturn = random.choice( [Turn.FIRST, Turn.SECOND] ) cputurn = Turn.FIRST if userturn == Turn.SECOND else Turn.SECOND userchip = Cells.FIRST_CHIP if userturn == Turn.FIRST else Cells.SECOND_CHIP cpuchip = Cells.FIRST_CHIP if cputurn == Turn.FIRST else Cells.SECOND_CHIP gamejudge.set_user_turn_order( userturn ) continue ## ユーザ入力 elif direction == Direction.USER_INPUT_BOARD_POSITION : poslist = gameboard.collect_valid_positions(userchip) if len(poslist) != 0 : pos = random.choice( poslist ) gamejudge.set_user_input_position(pos[0], pos[1]) print(f"{userturn.name}: choice {pos}") else : gamejudge.set_user_input_pass() print(f"{userturn.name}: pass") elif direction in (Direction.FIRST_TURN, Direction.SECOND_TURN) : poslist = gameboard.collect_valid_positions(cpuchip) if len(poslist) != 0 : pos = random.choice( poslist ) gamejudge.set_input_position(pos[0], pos[1]) print(f"{cputurn.name}: choice {pos}") else : gamejudge.set_input_pass() print(f"{cputurn.name}: pass") gamerenderer.display_gameboard( gameboard.get_gameboard() ) print(f"*** GAME OVER ***") first_count = 0 second_count = 0 for x in range(1,9) : for y in range(1,9) : if gameboard.get_gameboard_cell(x,y) == Cells.FIRST_CHIP : first_count += 1 if gameboard.get_gameboard_cell(x,y) == Cells.SECOND_CHIP : second_count += 1 print(f"FIRST:{first_count} SECOND:{second_count}") if first_count == second_count : print(f"draw game.") elif first_count > second_count : print("WINNER: FIRST!") else : print("WINNER: SECOND!")