def test_scan_King(self): new_score = score.Score() king = pieces.King(True, 2, 14) moves = [{'from_row': 2, 'from_col': 14, 'to_row': 1, 'to_col': 14, 'score': 43.0}, {'from_row': 2, 'from_col': 14, 'to_row': 1, 'to_col': 15, 'score': 5}, {'from_row': 2, 'from_col': 14, 'to_row': 2, 'to_col': 15, 'score': 5}, {'from_row': 2, 'from_col': 14, 'to_row': 3, 'to_col': 15, 'score': 5}, {'from_row': 2, 'from_col': 14, 'to_row': 3, 'to_col': 14, 'score': 5}, {'from_row': 2, 'from_col': 14, 'to_row': 3, 'to_col': 13, 'score': 5}, {'from_row': 2, 'from_col': 14, 'to_row': 1, 'to_col': 13, 'score': 5}] up = scans.scan_up(self.actual_board, king) up_right = scans.scan_up_right(self.actual_board, king) right = scans.scan_right(self.actual_board, king) down_right = scans.scan_down_right(self.actual_board, king) down = scans.scan_down(self.actual_board, king) down_left = scans.scan_down_left(self.actual_board, king) left = scans.scan_left(self.actual_board, king) up_left = scans.scan_up_left(self.actual_board, king) L = scans.scan_L(self.actual_board, king) player.scan(new_score, up, king, True) player.scan(new_score, up_right, king, True) player.scan(new_score, right, king, True) player.scan(new_score, down_right, king, True) player.scan(new_score, down, king, True) player.scan(new_score, down_left, king, True) player.scan(new_score, left, king, True) player.scan(new_score, up_left, king, True) player.scan(new_score, L, king, True) self.assertEqual(moves, new_score.play_moves)
def test_scan_Pawn(self): new_score = score.Score() pawn = pieces.Pawn(True, 2, 13) moves = [{'from_row': 2, 'from_col': 13, 'to_row': 1, 'to_col': 13, 'score': 60.15}, {'from_row': 2, 'from_col': 13, 'to_row': 1, 'to_col': 14, 'score': 43.0}] up = scans.scan_up(self.actual_board, pawn) up_right = scans.scan_up_right(self.actual_board, pawn) right = scans.scan_right(self.actual_board, pawn) down_right = scans.scan_down_right(self.actual_board, pawn) down = scans.scan_down(self.actual_board, pawn) down_left = scans.scan_down_left(self.actual_board, pawn) left = scans.scan_left(self.actual_board, pawn) up_left = scans.scan_up_left(self.actual_board, pawn) L = scans.scan_L(self.actual_board, pawn) player.scan(new_score, up, pawn, True) player.scan(new_score, up_right, pawn, True) player.scan(new_score, right, pawn, True) player.scan(new_score, down_right, pawn, True) player.scan(new_score, down, pawn, True) player.scan(new_score, down_left, pawn, True) player.scan(new_score, left, pawn, True) player.scan(new_score, up_left, pawn, True) player.scan(new_score, L, pawn, True) self.assertEqual(moves, new_score.play_moves)
def test_scan_bishop(self): new_score = score.Score() bishop = pieces.Bishop(False, 1, 14) moves = [{'from_row': 1, 'from_col': 14, 'to_row': 0, 'to_col': 15, 'score': -8}, {'from_row': 1, 'from_col': 14, 'to_row': 2, 'to_col': 15, 'score': -8}, {'from_row': 1, 'from_col': 14, 'to_row': 2, 'to_col': 13, 'score': -97}, {'from_row': 1, 'from_col': 14, 'to_row': 0, 'to_col': 13, 'score': -8}] up = scans.scan_up(self.actual_board, bishop) up_right = scans.scan_up_right(self.actual_board, bishop) right = scans.scan_right(self.actual_board, bishop) down_right = scans.scan_down_right(self.actual_board, bishop) down = scans.scan_down(self.actual_board, bishop) down_left = scans.scan_down_left(self.actual_board, bishop) left = scans.scan_left(self.actual_board, bishop) up_left = scans.scan_up_left(self.actual_board, bishop) L = scans.scan_L(self.actual_board, bishop) player.scan(new_score, up, bishop, True) player.scan(new_score, up_right, bishop, True) player.scan(new_score, right, bishop, True) player.scan(new_score, down_right, bishop, True) player.scan(new_score, down, bishop, True) player.scan(new_score, down_left, bishop, True) player.scan(new_score, left, bishop, True) player.scan(new_score, up_left, bishop, True) player.scan(new_score, L, bishop, True) self.assertEqual(moves, new_score.play_moves)
def scan_posible_moves(actual_board, color): new_score = score.Score() for i in range(16): for j in range(16): piece = actual_board.matrix_pieces[i][j] if not isinstance(piece, pieces.EmptySquare): up = scans.scan_up(actual_board, piece) up_right = scans.scan_up_right(actual_board, piece) right = scans.scan_right(actual_board, piece) down_right = scans.scan_down_right(actual_board, piece) down = scans.scan_down(actual_board, piece) down_left = scans.scan_down_left(actual_board, piece) left = scans.scan_left(actual_board, piece) up_left = scans.scan_up_left(actual_board, piece) L = scans.scan_L(actual_board, piece) scan(new_score, up, piece, color) scan(new_score, up_right, piece, color) scan(new_score, right, piece, color) scan(new_score, down_right, piece, color) scan(new_score, down, piece, color) scan(new_score, down_left, piece, color) scan(new_score, left, piece, color) scan(new_score, up_left, piece, color) scan(new_score, L, piece, color) return new_score
def test_set_score(self): score_new = score.Score() color = True white_queen = pieces.Queen(True, 8, 8) black_king = pieces.King(False, 0, 8) move = [{ 'from_row': 8, 'from_col': 8, 'to_row': 0, 'to_col': 8, 'score': 100.0 }] score_new.set_score(white_queen, black_king, color) self.assertEqual(move, score_new.play_moves)
def evaluate_moves(actual_board, actual_score, color): move_score = ([]) next_score = score.Score() for s in actual_score.play_moves: if s['score'] > 0: next_board = deepcopy(actual_board) next_board.matrix_pieces[s['to_row']][s['to_col']] = next_board.matrix_pieces[s['from_row']][s['from_col']] next_board.matrix_pieces[s['from_row']][s['from_col']] = pieces.EmptySquare(s['from_row'],s['from_col']) next_score = scan_posible_moves(next_board, color) max_move_now, _ = minimax(actual_score) max_move, min_move = minimax(next_score) points = s['score'] * 2 + max_move['score'] + min_move['score'] move_score.append([s, round(points, 2)]) return move_score
def setUp(self): self.board1 = ( '♖♙ ' '♙ ♝ ' ' ♙♔ ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ') self.actual_board = board.Board(self.board1) moves = ({'from_row': 1, 'from_col': 14, 'to_row': 0, 'to_col': 15, 'score': -8}, {'from_row': 1, 'from_col': 14, 'to_row': 2, 'to_col': 15, 'score': -8}, {'from_row': 1, 'from_col': 14, 'to_row': 2, 'to_col': 13, 'score': -97}, {'from_row': 1, 'from_col': 14, 'to_row': 0, 'to_col': 13, 'score': -8}, {'from_row': 2, 'from_col': 13, 'to_row': 1, 'to_col': 13, 'score': 60.15}, {'from_row': 2, 'from_col': 13, 'to_row': 1, 'to_col': 14, 'score': 43.0}, {'from_row': 2, 'from_col': 14, 'to_row': 1, 'to_col': 14, 'score': 43.0}, {'from_row': 2, 'from_col': 14, 'to_row': 1, 'to_col': 15, 'score': 5}, {'from_row': 2, 'from_col': 14, 'to_row': 2, 'to_col': 15, 'score': 5}, {'from_row': 2, 'from_col': 14, 'to_row': 3, 'to_col': 15, 'score': 5}, {'from_row': 2, 'from_col': 14, 'to_row': 3, 'to_col': 14, 'score': 5}, {'from_row': 2, 'from_col': 14, 'to_row': 3, 'to_col': 13, 'score': 5}, {'from_row': 2, 'from_col': 14, 'to_row': 1, 'to_col': 13, 'score': 5}) self.actual_score = score.Score() self.actual_score.play_moves = moves