def test_five_fold_is_not_draw(): # 1 g = BerkeleyGame() # 2 g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.F6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.G1))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F6, chess.G8))) # 3 g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.F6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.G1))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F6, chess.G8))) # 4 g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.F6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.G1))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F6, chess.G8))) # 5 g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.F6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.G1))) assert g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F6, chess.G8))) == KSAnswer(MA.REGULAR_MOVE)
def test_white_any_true(): g = BerkeleyGame() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E7, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D1, chess.H5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D7, chess.D5))) assert g.ask_for(KSMove(QA.ASK_ANY)) == KSAnswer(MA.HAS_ANY)
def test_five_fold_then_checkmate(): # 1 g = BerkeleyGame() # 2 g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.F6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.G1))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F6, chess.G8))) # 3 g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.F6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.G1))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F6, chess.G8))) # 4 g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.F6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.G1))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F6, chess.G8))) # 5 g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.F6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.G1))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F6, chess.G8))) # School checkmate g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E7, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.B8, chess.A6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F1, chess.C4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.A6, chess.B8))) assert g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.F7))) == KSAnswer( MA.CAPTURE_DONE, capture_at_square=chess.F7, special_announcement=SCA.CHECKMATE_WHITE_WINS)
def test_impossible_to_promotion_without_piece_spesification(): g = BerkeleyGame() g._board.clear() g._board.set_piece_at(chess.A7, chess.Piece(chess.PAWN, chess.WHITE)) g._board.set_piece_at(chess.H1, chess.Piece(chess.KING, chess.BLACK)) g._board.set_piece_at(chess.A1, chess.Piece(chess.KING, chess.WHITE)) g._generate_possible_to_ask_list() assert g.ask_for(KSMove(QA.COMMON, chess.Move( chess.A7, chess.A8))) == KSAnswer(MA.IMPOSSIBLE_TO_ASK)
def test_white_capture_en_passant(): g = BerkeleyGame() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.H6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E4, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F7, chess.F5))) assert g.ask_for(KSMove(QA.COMMON, chess.Move( chess.E5, chess.F6))) == KSAnswer(MA.CAPTURE_DONE, capture_at_square=chess.F5)
def test_black_illegal_after_any_true(): g = BerkeleyGame() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E7, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D1, chess.H5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D7, chess.D5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.H5, chess.G6))) g.ask_for(KSMove(QA.ASK_ANY)) # Legal in chess, but illegal after ask 'for any' assert g.ask_for(KSMove(QA.COMMON, chess.Move( chess.D8, chess.D7))) == KSAnswer(MA.IMPOSSIBLE_TO_ASK)
def test_check_rank(): g = BerkeleyGame() g._board.clear() g._board.set_piece_at(chess.B2, chess.Piece(chess.KING, chess.WHITE)) g._board.set_piece_at(chess.H8, chess.Piece(chess.KING, chess.BLACK)) g._board.set_piece_at(chess.D1, chess.Piece(chess.QUEEN, chess.BLACK)) g._generate_possible_to_ask_list() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.B2, chess.A3))) assert g.ask_for(KSMove(QA.COMMON, chess.Move( chess.D1, chess.D3))) == KSAnswer(MA.REGULAR_MOVE, special_announcement=SCA.CHECK_RANK)
def test_castling(): g = BerkeleyGame() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E7, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F1, chess.C4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F8, chess.C5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.H3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.H6))) assert g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E1, chess.G1))) == KSAnswer(MA.REGULAR_MOVE)
def test_stalemate(): g = BerkeleyGame() g._board.clear() g._board.set_piece_at(chess.C2, chess.Piece(chess.KING, chess.WHITE)) g._board.set_piece_at(chess.H8, chess.Piece(chess.KING, chess.BLACK)) g._board.set_piece_at(chess.G1, chess.Piece(chess.ROOK, chess.WHITE)) g._board.set_piece_at(chess.A1, chess.Piece(chess.ROOK, chess.WHITE)) g._generate_possible_to_ask_list() assert g.ask_for(KSMove(QA.COMMON, chess.Move(chess.A1, chess.A7))) == KSAnswer( MA.REGULAR_MOVE, special_announcement=SCA.DRAW_STALEMATE)
def test_black_legal_after_any_true(): g = BerkeleyGame() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E7, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D1, chess.H5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D7, chess.D5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.H5, chess.G6))) g.ask_for(KSMove(QA.ASK_ANY)) # Capture by pawn after ANY assert g.ask_for(KSMove(QA.COMMON, chess.Move( chess.D5, chess.E4))) == KSAnswer(MA.CAPTURE_DONE, capture_at_square=chess.E4)
def _ask_for(self, move): ''' return (MoveAnnouncement, captured_square, SpecialCaseAnnouncement) ''' # If player asks for non-sense move. Stop it. if move not in self.possible_to_ask: return KSAnswer(MA.IMPOSSIBLE_TO_ASK) if move.question_type == QA.COMMON: # Player asks about common move if self._is_legal_move(move.chess_move): # Move is legal in normal chess # Perform normal move captured_square = self._make_move(move.chess_move) special_case = self._check_special_cases() if captured_square is not None: # If it was capture return KSAnswer(MA.CAPTURE_DONE, capture_at_square=captured_square, special_announcement=special_case) # If it was regular move, and NO captures return KSAnswer(MA.REGULAR_MOVE, special_announcement=special_case) # If move is illegal for referee's perspective. But it's # was possible move from asking plaer's perspective. # IMPORTANT: That's a bit of new info for both players. return KSAnswer(MA.ILLEGAL_MOVE) elif move.question_type == QA.ASK_ANY: # Any Rule. Asking for any available pawn captures. # Possible to ask once a turn if self._has_any_pawn_captures(): self._must_use_pawns = True return KSAnswer(MA.HAS_ANY) else: return KSAnswer(MA.NO_ANY)
def test_promotion_check_long(): g = BerkeleyGame() g._board.clear() g._board.set_piece_at(chess.A7, chess.Piece(chess.PAWN, chess.WHITE)) g._board.set_piece_at(chess.H1, chess.Piece(chess.KING, chess.BLACK)) g._board.set_piece_at(chess.A1, chess.Piece(chess.KING, chess.WHITE)) g._generate_possible_to_ask_list() assert g.ask_for( KSMove(QA.COMMON, chess.Move(chess.A7, chess.A8, promotion=chess.QUEEN))) == KSAnswer( MA.REGULAR_MOVE, special_announcement=SCA.CHECK_LONG_DIAGONAL)
def test_white_wins(): g = BerkeleyGame() g._board.clear() g._board.set_piece_at(chess.C2, chess.Piece(chess.KING, chess.WHITE)) g._board.set_piece_at(chess.H8, chess.Piece(chess.KING, chess.BLACK)) g._board.set_piece_at(chess.G1, chess.Piece(chess.ROOK, chess.WHITE)) g._board.set_piece_at(chess.B7, chess.Piece(chess.QUEEN, chess.WHITE)) g._board.set_piece_at(chess.A1, chess.Piece(chess.ROOK, chess.WHITE)) g._generate_possible_to_ask_list() assert g.ask_for(KSMove(QA.COMMON, chess.Move(chess.A1, chess.A8))) == KSAnswer( MA.REGULAR_MOVE, special_announcement=SCA.CHECKMATE_WHITE_WINS)
def test_illegal_to_castling_through_check(): g = BerkeleyGame() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E7, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F1, chess.C4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F8, chess.C5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.H3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.H6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F2, chess.F4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.B8, chess.A6))) assert g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E1, chess.G1))) == KSAnswer(MA.ILLEGAL_MOVE)
def test_check_short_diagonal_upper_left_quadrant(): g = BerkeleyGame() g._board.clear() g._board.set_piece_at(chess.B8, chess.Piece(chess.KING, chess.WHITE)) g._board.set_piece_at(chess.B7, chess.Piece(chess.QUEEN, chess.WHITE)) g._board.set_piece_at(chess.H8, chess.Piece(chess.KING, chess.BLACK)) g._board.set_piece_at(chess.G1, chess.Piece(chess.QUEEN, chess.BLACK)) g._board.turn = chess.BLACK g._generate_possible_to_ask_list() assert g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.A7))) == KSAnswer( MA.REGULAR_MOVE, special_announcement=SCA.CHECK_SHORT_DIAGONAL)
def test_draw_insufficient(): g = BerkeleyGame() g._board.clear() g._board.set_piece_at(chess.A8, chess.Piece(chess.QUEEN, chess.WHITE)) g._board.set_piece_at(chess.F7, chess.Piece(chess.KING, chess.WHITE)) g._board.set_piece_at(chess.G4, chess.Piece(chess.BISHOP, chess.WHITE)) g._board.set_piece_at(chess.D4, chess.Piece(chess.KING, chess.BLACK)) g._generate_possible_to_ask_list() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.A8, chess.D5))) assert g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D4, chess.D5))) == KSAnswer( MA.CAPTURE_DONE, capture_at_square=chess.D5, special_announcement=SCA.DRAW_INSUFFICIENT)
def test_black_from_check_false(): g = BerkeleyGame() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E7, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D1, chess.H5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D7, chess.D5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.H5, chess.G6))) g.ask_for(KSMove(QA.ASK_ANY)) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D5, chess.E4))) g.ask_for(KSMove(QA.ASK_ANY)) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G6, chess.F7))) assert g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E8, chess.E7))) == KSAnswer(MA.ILLEGAL_MOVE)
def test_200_reversible_moves(): g = BerkeleyGame() for _ in range(499): g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.F6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.G1))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F6, chess.G8))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.F6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.G1))) assert g.ask_for(KSMove(QA.COMMON, chess.Move( chess.F6, chess.G8))) == KSAnswer( MA.REGULAR_MOVE, special_announcement=SCA.DRAW_TOOMANYREVERSIBLEMOVES)
def test_check_double(): g = BerkeleyGame() g._board.clear() g._board.set_piece_at(chess.C2, chess.Piece(chess.KING, chess.WHITE)) g._board.set_piece_at(chess.H8, chess.Piece(chess.KING, chess.BLACK)) g._board.set_piece_at(chess.E2, chess.Piece(chess.QUEEN, chess.BLACK)) g._board.set_piece_at(chess.D2, chess.Piece(chess.KNIGHT, chess.BLACK)) g._generate_possible_to_ask_list() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.C2, chess.B2))) assert g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D2, chess.C4))) == KSAnswer( MA.REGULAR_MOVE, special_announcement=(SCA.CHECK_DOUBLE, [ SCA.CHECK_RANK, SCA.CHECK_KNIGHT ]))
def test_white_capture_and_check(): g = BerkeleyGame() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E7, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D1, chess.H5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D7, chess.D5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.H5, chess.G6))) g.ask_for(KSMove(QA.ASK_ANY)) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D5, chess.E4))) g.ask_for(KSMove(QA.ASK_ANY)) assert g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G6, chess.F7))) == KSAnswer( MA.CAPTURE_DONE, capture_at_square=chess.F7, special_announcement=SCA.CHECK_SHORT_DIAGONAL)
def test_black_from_check_true_and_capture(): g = BerkeleyGame() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E7, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D1, chess.H5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D7, chess.D5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.H5, chess.G6))) g.ask_for(KSMove(QA.ASK_ANY)) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D5, chess.E4))) g.ask_for(KSMove(QA.ASK_ANY)) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G6, chess.F7))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E8, chess.E7))) assert g.ask_for(KSMove(QA.COMMON, chess.Move( chess.E8, chess.F7))) == KSAnswer(MA.CAPTURE_DONE, capture_at_square=chess.F7)
def test_promotion_capture_draw(): g = BerkeleyGame() g._board.clear() g._board.set_piece_at(chess.B8, chess.Piece(chess.KING, chess.BLACK)) g._board.set_piece_at(chess.B2, chess.Piece(chess.PAWN, chess.BLACK)) g._board.set_piece_at(chess.H8, chess.Piece(chess.KING, chess.WHITE)) g._board.set_piece_at(chess.A1, chess.Piece(chess.QUEEN, chess.WHITE)) g._board.turn = chess.BLACK g._generate_possible_to_ask_list() assert g.ask_for( KSMove(QA.COMMON, chess.Move(chess.B2, chess.A1, promotion=chess.BISHOP))) == KSAnswer( MA.CAPTURE_DONE, capture_at_square=chess.A1, special_announcement=SCA.DRAW_INSUFFICIENT)
def test_impossible_ask_castling_after_move(): g = BerkeleyGame() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E7, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F1, chess.C4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F8, chess.C5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.H3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G8, chess.H6))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F2, chess.F4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F7, chess.F5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E1, chess.E2))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.C5, chess.F8))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E1))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.H8, chess.G8))) assert g.ask_for(KSMove(QA.COMMON, chess.Move( chess.E1, chess.G1))) == KSAnswer(MA.IMPOSSIBLE_TO_ASK)
def test_black_any_true_en_passant(): g = BerkeleyGame() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E7, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D1, chess.H5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D7, chess.D5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.H5, chess.G6))) g.ask_for(KSMove(QA.ASK_ANY)) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D5, chess.E4))) g.ask_for(KSMove(QA.ASK_ANY)) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G6, chess.F7))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E8, chess.E7))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E8, chess.F7))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E4, chess.E3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.G1))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E5, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F2, chess.F4))) assert g.ask_for(KSMove(QA.ASK_ANY)) == KSAnswer(MA.HAS_ANY)
def test_black_capture_en_passant(): g = BerkeleyGame() g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E2, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E7, chess.E5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D1, chess.H5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D7, chess.D5))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.H5, chess.G6))) g.ask_for(KSMove(QA.ASK_ANY)) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.D5, chess.E4))) g.ask_for(KSMove(QA.ASK_ANY)) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G6, chess.F7))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E8, chess.E7))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E8, chess.F7))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.G1, chess.F3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E4, chess.E3))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F3, chess.G1))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.E5, chess.E4))) g.ask_for(KSMove(QA.COMMON, chess.Move(chess.F2, chess.F4))) g.ask_for(KSMove(QA.ASK_ANY)) assert g.ask_for(KSMove(QA.COMMON, chess.Move( chess.E4, chess.F3))) == KSAnswer(MA.CAPTURE_DONE, capture_at_square=chess.F4)
def test_special_annoucement(): a = KSAnswer(MA.REGULAR_MOVE, special_announcement=SCA.CHECK_RANK) assert a.special_announcement == SCA.CHECK_RANK
def test_captue_at_square(): a = KSAnswer(MA.CAPTURE_DONE, capture_at_square=chess.E2) assert a.capture_at_square == chess.E2
def test_SCA_not_tuple_or_SCA(): with pytest.raises(TypeError): KSAnswer(MA.REGULAR_MOVE, special_announcement='Unexpected type.')
def test_if_tuple_but_nondouble_check(): with pytest.raises(TypeError): KSAnswer(MA.REGULAR_MOVE, special_announcement=('Nondouble check.', [SCA.CHECK_DOUBLE, SCA.CHECK_KNIGHT]))
def test_double_check_but_not_single_checks(): with pytest.raises(TypeError): KSAnswer(MA.REGULAR_MOVE, special_announcement=(SCA.CHECK_DOUBLE, [SCA.CHECK_DOUBLE, SCA.CHECK_KNIGHT]))