import random import gameboard as gb import gamejudge as gj import gameui as gu from gameconstants import Cells from gameconstants import Turn from gamejudge import Direction from gameui import InputResult ## demo gameboard = gb.GameBoard() gamejudge = gj.GameJudge( gameboard ) ## share gameboard with GameJudge instance gameUI = gu.GameUI( gameboard ) ## share gameboard with GameUI instance userchip = Cells.UNKNOWN userturn = Turn.NOT_YET cpuchip = Cells.UNKNOWN cputurn = Turn.NOT_YET while 1==1 : gameUI.draw_board() direction = gamejudge.get_instruction() ## ゲーム終了 if direction == Direction.GAMEOVER : break ## ユーザの先手後手選択 elif direction == Direction.USER_INPUT_TURN_ORDER : userturn = gameUI.select_side() if userturn == Turn.QUIT : break 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 : result, pos = gameUI.input_position() if result == InputResult.QUIT : break; else : gamejudge.set_user_input_position(pos[0], pos[1]) else : gamejudge.set_user_input_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]) else : gamejudge.set_input_pass() gameUI.draw_finish_screen()