Пример #1
0
def main():
    """the main gameplay loop"""
    game = XiangqiGame()  # initializes game
    while True:
        clear_screen()  # start by clearing screen
        print("Type 'q' at any time to forfeit")
        print()
        game.show_board()
        print()
        print('Game state:', game.get_game_state())
        print('Turn:', game.get_turn(), end='')
        if game.is_in_check(game.get_turn().lower()):
            print(' (in check)')
        print()
        print()

        move_from = input('Move from: ')
        if move_from == 'q':
            if game.get_turn() == 'RED':
                print('BLACK_WON')
            if game.get_turn() == 'BLACK':
                print('RED_WON')
            time.sleep(1)
            break

        move_to = input('Move to: ')
        if move_to == 'q':
            break

        if not game.make_move(move_from, move_to):
            print("Invalid move. Try again.")
            time.sleep(1)
        else:
            game.make_move(move_from, move_to)
Пример #2
0
 def test_real_game_1(self):
     """
     The following code is a game copied from an online match found at:
     http://wxf.ca/wxf/index.php/xiangqi-news/news-from-europ/381-world-xiangqi-championships-2015-game-records
     :return:
     """
     game = XiangqiGame()
     game.make_move('g4', 'g5')
     game.make_move('c7', 'c6')
     game.make_move('b3', 'c3')
     game.make_move('c10', 'e8')
     game.make_move('b1', 'a3')
     game.make_move('b8', 'b4')
     game.make_move('h1', 'g3')
     game.make_move('b10', 'c8')
     game.make_move('g1', 'e3')
     game.make_move('c8', 'd6')
     game.make_move('a1', 'b1')
     game.make_move('a10', 'b10')
     game.make_move('f1', 'e2')
     game.make_move('b4', 'b2')
     game.make_move('i1', 'f1')
     game.make_move('f10', 'e9')
     game.make_move('f1', 'f6')
     game.make_move('d6', 'c8')
     game.make_move('a4', 'a5')
     game.make_move('b10', 'b3')
     game.make_move('c3', 'd3')
     game.make_move('c8', 'b6')
     game.make_move('g3', 'f5')
     game.make_move('b6', 'c4')
     game.make_move('d3', 'd9')
     game.make_move('c4', 'a3')
     game.make_move('h3', 'b3')
     game.make_move('a3', 'b1')
     game.make_move('b3', 'b10')
     self.assertEqual(game.get_game_state(), 'RED_WON')
Пример #3
0
 def test_init_state(self):
     game = XiangqiGame()
     self.assertEqual(game.get_game_state(), "UNFINISHED")