def test_is_main_piece(self): # basic case expected = True for piece in ['K','Q','N','B','R']: actual = cm.is_main_piece(piece +'1') self.assertEqual(expected, actual) # real moves expected = True for input_move in ['Kf3','Bxa2','Rxd2']: actual = cm.is_main_piece(input_move) self.assertEqual(expected, actual) # wrong moves expected = False for input_move in ['q','axc1','b3']: actual = cm.is_main_piece(input_move) self.assertEqual(expected, actual)
def validate_eat_case(input_move): if len(input_move) < 4 or \ input_move[-3] != 'x' or \ (not are_coordinates_valid(input_move[-2], input_move[-1])): return False return ( ( len(input_move) == 4 and (cm.is_pawn(input_move) or cm.is_main_piece(input_move)) ) or ( len(input_move) == 5 and ( cm.is_main_piece(input_move)) and ( input_move[1] in utils.COLUMN_NAMES + utils.LINE_NAMES ) ) or ( len(input_move) == 6 and ( cm.is_main_piece(input_move)) and ( are_coordinates_valid(input_move[1], input_move[2]) ) ) )
def parse_coordinates(input_move): if cm.is_pawn(input_move): move_to_col, move_to_line, col_filter, line_filter = parse_pawn_coordinates(input_move) elif cm.is_main_piece(input_move): move_to_col, move_to_line, col_filter, line_filter = parse_main_pieces_coordinates(input_move) else: move_to_col, move_to_line = None, None col_filter, line_filter = None, None return move_to_col, move_to_line, col_filter, line_filter
def validate_move_case(input_move): if cm.is_pawn(input_move): return len(input_move) == 2 and input_move[1] in utils.LINE_NAMES if (not cm.is_main_piece(input_move) )or \ not are_coordinates_valid(input_move[-2], input_move[-1]): return False return ( len(input_move) == 3 or ( input_move[1] in utils.COLUMN_NAMES+ utils.LINE_NAMES and len(input_move) == 4 ) or ( are_coordinates_valid(input_move[1], input_move[2]) and len(input_move) == 5 ) )
def is_user_move_valid(input_move): if len(input_move) <= 1: print 'wrong input try again' return False if cm.is_check(input_move): print "CHECK" input_move = input_move[:-1] if cm.is_castling(input_move): return True if cm.is_special_case(input_move): return True if not cm.is_pawn(input_move) and not cm.is_main_piece(input_move): print 'case not valid, not a chess piece' return False if validate_eat_case(input_move): print 'valid eat input' return True if validate_move_case(input_move): print 'valid move input' return True promotion,input_move,promoted_to = cm.is_promotion(input_move) if promotion: if not is_valid_promotion(input_move,promoted_to): return False else: return True print 'wrong input, try again' return False