Esempio n. 1
0
def printEnd(lowers_turn, last_cmd):
    global upper_captured
    global lower_captured
    global gameBoard
    print("{} player action: {}".format('UPPER' if lowers_turn else 'lower',
                                        last_cmd))
    print(utils.stringifyBoard(gameBoard_to_stringBoard(gameBoard)))
    #print ("")
    print("Captures UPPER:", *[p.piece_type for p in upper_captured])
    print("Captures lower:", *[p.piece_type for p in lower_captured])
    print("")
    if (checkDetection(gameBoard, lowers_turn)):
        avail_moves = getOutOfCheckMoves(gameBoard, lowers_turn)
        if (len(avail_moves) == 0):
            print("{} wins. Checkmate.".format(
                'UPPER' if lowers_turn else 'lower'))
            exit(0)
        else:
            print("{} player is in check!".format(
                'lower' if lowers_turn else 'UPPER'))
            print("Available moves:")
            for m in avail_moves:
                print("move {} {}".format(coord_to_pos(m[0]),
                                          coord_to_pos(m[1])))
    print("lower> " if lowers_turn else "UPPER> ")
    print("")
Esempio n. 2
0
 def __repr__(self):
     ''' Used to distiguish Board objects for logging. '''
     str_board = [['' for _ in range(const.BOARD_SIZE)]
                  for _ in range(const.BOARD_SIZE)]
     for a in range(const.BOARD_SIZE):
         for b in range(const.BOARD_SIZE):
             str_board[a][b] = str(self.board[a][b])
     return utils.stringifyBoard(str_board)
Esempio n. 3
0
def print_game(game):
    lower_or_upper = "lower" if game.current_player == 0 else "UPPER"

    print utils.stringifyBoard(game.board.board_matrix)
    print "Captures UPPER: " + " ".join(
        [str.upper(x) for x in game.player2.droppable])
    print "Captures lower: " + " ".join(game.player1.droppable) + "\n"

    player = game.id_to_player(game.current_player)
    if player.in_check:
        moves, drops = game.board.find_all_moves_and_drops_no_check(player)
        moves = sorted([move_to_notation(x) for x in moves])
        drops = sorted([drop_to_notation(x) for x in drops])
        print lower_or_upper + " player is in check!\nAvailable moves:"
        for drop in drops:
            print drop
        for move in moves:
            print move
    print("lower> " if game.current_player == 0 else "UPPER> "),
Esempio n. 4
0
    def win(self, player_id, reason):
        current_lower_or_upper = "lower" if self.current_player == 0 else "UPPER"
        lower_or_upper = "lower" if player_id == 0 else "UPPER"

        print current_lower_or_upper + " player action: " + self.command

        print utils.stringifyBoard(self.board.board_matrix)
        print "Captures UPPER: " + " ".join(
            [str.upper(x) for x in self.player2.droppable])
        print "Captures lower: " + " ".join(self.player1.droppable) + "\n"

        if reason == "disqualified":
            print lower_or_upper + " player wins.  Illegal move."

        elif reason == "checkmated":
            print lower_or_upper + " player wins.  Checkmate."
        elif reason == "tie":
            print "Tie game.  Too many moves."

        exit(0)
Esempio n. 5
0
def printBeginTurn(game, listToPrint):
    """
        Called at the beginning of every turn
        Prints the board, Captured pieces, and available moves if the player is in check
        Returns: Nothing
    """
    #Empty last move (beginning of the game)
    if game.prevMove != "":
        printPrevCommand(game)

    #Uodate string representation of the board
    game.refreshStrBoard()
    #Call utility function
    strB = utils.stringifyBoard(game.strBoard)
    print(strB)

    #Print upper capture pieces
    print("Captures UPPER:", end="")
    for item in game.upperPlayer.captures:
        print(" " + str(item), end="")

    print("")

    #Print lower capture pieces
    print("Captures lower:", end="")
    for item in game.lowerPlayer.captures:
        print(" " + str(item), end="")

    print("")

    #If player is in check, show available moves to get out of it
    if game.playerInCheck == True:
        print("")
        print(game.playerTurn + " player is in check!")
        print("Available moves:")
        printList(listToPrint)
    else:
        print("")

    return
Esempio n. 6
0
 def __str__(self):
     """ Board string representation """
     return stringifyBoard(self.board)
Esempio n. 7
0
 def display(self):
     print(utils.stringifyBoard(self._board._board))
     print('Captures UPPER: %s' %
           ' '.join(self._captures.getCaptures(config.UPPER_PLAYER)))
     print('Captures lower: %s\n' %
           ' '.join(self._captures.getCaptures(config.LOWER_PLAYER)))
Esempio n. 8
0
    printEnd(lowers_turn, last_cmd)
    if moves_count >= MOVES_LIMIT:
        print("Tie game. Too many moves.")
        exit(0)

else:

    init_gameBoard(gameBoard)
    lowers_turn = True
    last_cmd = ''
    while moves_count < MOVES_LIMIT:
        moves_count += 1
        if moves_count > 1:
            print("{} player action: {}".format(
                'UPPER' if lowers_turn else 'lower', last_cmd))
        print(utils.stringifyBoard(gameBoard_to_stringBoard(gameBoard)))
        print("")
        print("Captures UPPER:", *[p.piece_type for p in upper_captured])
        print("Captures lower:", *[p.piece_type for p in lower_captured])
        print("")
        if (checkDetection(gameBoard, lowers_turn)):
            avail_moves = getOutOfCheckMoves(gameBoard, lowers_turn)
            if (len(avail_moves) == 0):
                print("{} wins. Checkmate.".format(
                    'UPPER' if lowers_turn else 'lower'))
                exit(0)
            else:
                print("{} player is in check!".format(
                    'lower' if lowers_turn else 'UPPER'))
                print("Available moves:")
                for m in avail_moves: