示例#1
0
 def create_start_board(self):
     board = []
     for row in range(8):
         board_row = []
         for column in range(8):
             if row < 3:
                 if row == 0 or row == 2:
                     if column % 2 != 0:
                         board_row.append(Piece(row, column, self.BLACK))
                     else:
                         board_row.append(EmptyPiece())
                 else:
                     if column % 2 != 0:
                         board_row.append(EmptyPiece())
                     else:
                         board_row.append(Piece(row, column, self.BLACK))
             elif 2 < row < 5:
                 board_row.append(EmptyPiece())
             else:
                 if row == 5 or row == 7:
                     if column % 2 == 0:
                         board_row.append(Piece(row, column, self.RED))
                     else:
                         board_row.append(EmptyPiece())
                 else:
                     if column % 2 == 0:
                         board_row.append(EmptyPiece())
                     else:
                         board_row.append(Piece(row, column, self.RED))
         board.append(board_row)
     return board
示例#2
0
    def eat_piece_in_board(self, current_piece, new_piece, direction):
        # Set an empty space in the place where the piece was
        self.board[current_piece.row][current_piece.col] = EmptyPiece()
        # Set an empty space in the place where the other's team piece was
        self.board[new_piece.row][new_piece.col] = EmptyPiece()

        # If eating towards the left
        if direction == Direction.LEFT:
            # Move the piece to the left
            moved_to_left = new_piece.move_left()
            # Set the piece in that space. It should be an empty space because this method
            # is called after is_eating_position
            self.board[moved_to_left.row][moved_to_left.col] = moved_to_left
            return moved_to_left
        elif direction == Direction.RIGHT:
            moved_to_right = new_piece.move_right()
            self.board[moved_to_right.row][moved_to_right.col] = moved_to_right
            return moved_to_right
        elif direction == Direction.LEFT_BACKWARDS:
            moved_to_left_backwards = new_piece.move_left_backwards()
            self.board[moved_to_left_backwards.row][
                moved_to_left_backwards.col] = moved_to_left_backwards
            return moved_to_left_backwards
        elif direction == Direction.RIGHT_BACKWARDS:
            moved_to_right_backwards = new_piece.move_right_backwards()
            self.board[moved_to_right_backwards.row][
                moved_to_right_backwards.col] = moved_to_right_backwards
            return moved_to_right_backwards
示例#3
0
    def eat_piece(self, matrix, possible_boards, current_piece, new_piece, direction):
        # Set an empty space in the place where the piece was
        matrix[current_piece.row][current_piece.col] = EmptyPiece()
        # Set an empty space in the place where the other's team piece was
        matrix[new_piece.row][new_piece.col] = EmptyPiece()

        # If eating towards the left
        if direction == Direction.LEFT:
            # Move the piece to the left
            moved_to_left = new_piece.move_left()
            # Set the piece in that space. It should be an empty space because this method
            # is called after is_eating_position
            matrix[moved_to_left.row][moved_to_left.col] = moved_to_left
            # Create the new board but not append it to the result because it might be possible to keep eating pieces
            new_board = Board(self.RED, self.BLACK, matrix)
            self.try_to_keep_eating(new_board, matrix, possible_boards, moved_to_left)
        elif direction == Direction.RIGHT:
            moved_to_right = new_piece.move_right()
            matrix[moved_to_right.row][moved_to_right.col] = moved_to_right
            new_board = Board(self.RED, self.BLACK, matrix)
            self.try_to_keep_eating(new_board, matrix, possible_boards, moved_to_right)
        elif direction == Direction.LEFT_BACKWARDS:
            moved_to_left_backwards = new_piece.move_left_backwards()
            matrix[moved_to_left_backwards.row][moved_to_left_backwards.col] = moved_to_left_backwards
            new_board = Board(self.RED, self.BLACK, matrix)
            self.try_to_keep_eating(new_board, matrix, possible_boards, moved_to_left_backwards)
        elif direction == Direction.RIGHT_BACKWARDS:
            moved_to_right_backwards = new_piece.move_right_backwards()
            matrix[moved_to_right_backwards.row][moved_to_right_backwards.col] = moved_to_right_backwards
            new_board = Board(self.RED, self.BLACK, matrix)
            self.try_to_keep_eating(new_board, matrix, possible_boards, moved_to_right_backwards)
示例#4
0
 def create_empty_board_matrix(self):
     board = []
     for row in range(8):
         board_row = []
         for column in range(8):
             board_row.append(EmptyPiece())
         board.append(board_row)
     return board
示例#5
0
 def move_piece_in_board(self, current_piece, new_piece, direction):
     piece_in_place = self.board[new_piece.row][new_piece.col]
     # Piece is moving to an empty space
     if type(piece_in_place) == EmptyPiece:
         self.board[current_piece.row][current_piece.col] = EmptyPiece()
         self.board[new_piece.row][new_piece.col] = new_piece
         # First argument is if a piece was eaten
         return False, new_piece
     # Piece is eating an opposite piece
     else:
         # Eat pieces recursively and add all the possible results
         return True, self.eat_piece_in_board(current_piece, new_piece, direction)
示例#6
0
 def move_piece(self, current_piece, new_piece, direction):
     possible_boards = []
     new_board_matrix = self.copy_board_matrix(self.board)
     piece_in_place_of_new = new_board_matrix[new_piece.row][new_piece.col]
     # Piece is moving to an empty space
     if type(piece_in_place_of_new) == EmptyPiece:
         new_board_matrix[current_piece.row][current_piece.col] = EmptyPiece()
         new_board_matrix[new_piece.row][new_piece.col] = new_piece
         possible_boards.append(Board(self.RED, self.BLACK, new_board_matrix))
         # if type(new_piece) == KingPiece and type(current_piece) == Piece:
         #     possible_boards.append([Board(self.RED, self.BLACK, new_board_matrix), MoveKind.CROWNED])
         # else:
         #     possible_boards.append([Board(self.RED, self.BLACK, new_board_matrix), MoveKind.NORMAL])
         return possible_boards
         # Piece is eating an opposite piece
     else:
         # Eat pieces recursively and add all the possible results
         self.eat_piece(new_board_matrix, possible_boards, current_piece, new_piece, direction)
         return possible_boards
示例#7
0
def print_board(board_to_print):
    for row in board_to_print.board:
        row_pieces = []
        for piece in row:
            row_pieces.append(piece.symbol)
        print("|" + "|".join(row_pieces) + "|")


RED = Player(True, "RED", game_pieces.RED_PIECE, game_pieces.RED_KING_PIECE)
BLACK = Player(False, "BLACK", game_pieces.BLACK_PIECE,
               game_pieces.BLACK_KING_PIECE)
board = Board(RED, BLACK)

# random piece placements to test
king = KingPiece(3, 1, BLACK)
board.board[0][0] = EmptyPiece()
board.board[0][1] = EmptyPiece()
board.board[0][2] = EmptyPiece()
board.board[0][3] = EmptyPiece()
board.board[0][4] = EmptyPiece()
board.board[0][5] = EmptyPiece()
board.board[0][6] = EmptyPiece()
board.board[0][7] = EmptyPiece()

board.board[1][0] = Piece(1, 0, BLACK)
board.board[1][1] = EmptyPiece()
board.board[1][2] = Piece(1, 2, BLACK)
board.board[1][3] = EmptyPiece()
board.board[1][4] = EmptyPiece()
board.board[1][5] = EmptyPiece()
board.board[1][6] = EmptyPiece()
    possible_boards_for_piece = board.get_possible_boards(movable_pieces)
    for possible_board in possible_boards_for_piece:
        print_board(possible_board)
        print("\n")"""

# possible_boards_for_piece = board.get_possible_boards(board.board[5][0])
# for possible_board in possible_boards_for_piece:
#     print_board(possible_board)
#     print("\n")
#
# print(board.get_score_for_player(top_player))
# print(board.get_score_for_player(bottom_player))
# print(board.get_winner())

board.board[3][2] = Piece(3, 2, RED)
board.board[5][4] = EmptyPiece()

print_board(board)
print("\n")

game = Algorithm()
next_board = game.iterative_deepening(board, 2, BLACK, RED)[1]

print_board(next_board)
print("\n")

next_board.board[3][4] = Piece(3, 4, RED)
next_board.board[5][2] = EmptyPiece()
next_board.board[4][3] = EmptyPiece()

print_board(next_board)
from player import Player


def print_board(board_to_print):
    for row in board_to_print.board:
        row_pieces = []
        for piece in row:
            row_pieces.append(piece.symbol)
        print("|" + "|".join(row_pieces) + "|")


RED = Player(True, "RED", game_pieces.RED_PIECE, game_pieces.RED_KING_PIECE)
BLACK = Player(False, "BLACK", game_pieces.BLACK_PIECE,
               game_pieces.BLACK_KING_PIECE)
board = Board(RED, BLACK)

# random piece placements to test
king = KingPiece(3, 1, BLACK)
board.board[3][1] = king
board.board[4][2] = Piece(4, 2, RED)
board.board[6][3] = EmptyPiece()
board.board[6][7] = EmptyPiece()
board.board[7][4] = EmptyPiece()

print_board(board)
print("\n")

possible_king_boards = board.get_possible_boards_for_piece(king)
for possible_board in possible_king_boards:
    print_board(possible_board)
    print("\n")