Ejemplo n.º 1
0
def StartGame():
    b = Board(4)

    player_index = 0
    moves = 0

    outcome = (False, 0)

    while outcome[0] == False:
        player_index = moves % 2
        cur_player = player[player_index]

        color_txt = Board.Color2Text[cur_player.color]
        print("{} to move!".format(color_txt))
        print(b)
        print("---")

        # Get the point that the current player is going to play
        pt = cur_player.PlayMove(b)
        # Color the current point
        b.ColorPoint(pt, cur_player.color)

        print("{} plays {}!".format(color_txt, pt))
        print(b)
        print(">>>")

        moves += 1

        outcome = b.DetectGameEnd()

    print("{} wins!".format(Board.Color2Text[outcome[1]]))

    return
Ejemplo n.º 2
0
class Game:
    ### Built-in Class Methods ###
    def __init__(self, board_size):
        self.board = Board(board_size)

    ### Public Methods ###
    def Start(self):
        Prompt.ShowBanner()
        u_input = Prompt.WelcomePrompt()

        if u_input == 0:
            print("Quitting.")
            return
        elif u_input == 1:
            self.PlayGame(None, Agent(Board.BLACK))
        elif u_input == 2:
            self.PlayGame(Agent(Board.WHITE), Player(Board.BLACK))
        else:
            print("Error, unknown option cannot be caught.")
            return

        return

    def PlayGame(self, white_player, black_player):
        player_color = (Board.WHITE, Board.BLACK)

        players = {Board.WHITE: white_player, Board.BLACK: black_player}

        moves = 0

        outcome = (False, 0)

        while outcome[0] == False:
            time.sleep(1)
            color = player_color[moves % 2]
            player_to_move = Board.Color2Text[color]

            moves += 1

            # Retrieve the player from the dictionary
            cur_player = players[color]

            # Display the board state for context
            Prompt.DisplayBoardState(self.board, player_to_move, moves)

            # Select point to be played
            point_to_play = None
            if (cur_player is not None):
                point_to_play = cur_player.PlayMove(self.board)
            else:
                point_to_play = Prompt.PromptAndPlayMove(
                    self.board, player_to_move, moves)

            # #TEMPORARY DEBUG STATEMENT - REMOVE LATER
            # if (moves == 20):
            #     print("20 moves reched")
            #     return
            # #END OF DEBUG STATEMENT

            # Color the point on the board
            self.board.ColorPoint(point_to_play, color)

            # Report the move
            Prompt.ReportMove(self.board, player_to_move, point_to_play)

            outcome = self.board.DetectGameEnd()

        winner = Board.Color2Text[outcome[1]]
        Prompt.DisplayGameOver(winner)