Exemple #1
0
    def setUp(self):
        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.database_persp = Database()
        perspective_manager.add_perspective(self.database_persp)
        self.database_persp.create_toolbuttons()
Exemple #2
0
    def setUp(self):
        EmittingTestCase.setUp(self)
        self.manager = self.connection.bm

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.fics_persp = FICS()
        perspective_manager.add_perspective(self.fics_persp)

        self.fics_persp.connection = self.connection
        self.connection.bm.connect("obsGameCreated", self.fics_persp.onObserveGameCreated)
Exemple #3
0
    def setUp(self):
        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.learn_persp = Learn()
        perspective_manager.add_perspective(self.learn_persp)
Exemple #4
0
    def setUp(self):
        if sys.platform == "win32":
            from asyncio.windows_events import ProactorEventLoop
            loop = ProactorEventLoop()
            asyncio.set_event_loop(loop)
        else:
            loop = asyncio.SelectorEventLoop()
            asyncio.set_event_loop(loop)

        self.loop = asyncio.get_event_loop()
        self.loop.set_debug(enabled=True)

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)
Exemple #5
0
    def setUp(self):
        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.database_persp = Database()
        perspective_manager.add_perspective(self.database_persp)
        self.database_persp.create_toolbuttons()
Exemple #6
0
    def testPolyglot_2(self):
        """Testing Polyglot book creation"""

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.database_persp = Database()
        self.database_persp.create_toolbuttons()
        perspective_manager.add_perspective(self.database_persp)

        self.database_persp.open_chessfile(PGN)

        @asyncio.coroutine
        def coro():
            def on_book_created(persp, event):
                self.assertTrue(os.path.isfile(BIN))

                testcase = testcases[0]
                board = LBoard(Board)
                board.applyFen(testcase[0])
                openings = book.getOpenings(board)
                self.assertEqual(
                    sorted(openings),
                    sorted([(newMove(E2, E4), 2, 0), (newMove(A2, A4), 0, 0)]))

                testcase = testcases[-1]
                board = LBoard(Board)
                board.applyFen(testcase[0])
                openings = book.getOpenings(board)
                self.assertEqual(openings, [])

                event.set()

            event = asyncio.Event()
            self.database_persp.connect("bookfile_created", on_book_created,
                                        event)

            self.database_persp.create_book(BIN)

            yield from event.wait()

        loop = asyncio.get_event_loop()
        loop.set_debug(enabled=True)

        loop.run_until_complete(coro())
Exemple #7
0
    def setUp(self):
        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.learn_persp = Learn()
        self.learn_persp.create_toolbuttons()
        perspective_manager.add_perspective(self.learn_persp)

        perspective_manager.current_perspective = self.learn_persp

        dd = DiscovererDialog(discoverer)
        self.dd_task = create_task(dd.start())
    def setUp(self):
        EmittingTestCase.setUp(self)
        self.loop.set_debug(enabled=True)

        self.manager = self.connection.bm

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.fics_persp = FICS()
        perspective_manager.add_perspective(self.fics_persp)

        self.fics_persp.connection = self.connection
        self.connection.bm.connect("obsGameCreated", self.fics_persp.onObserveGameCreated)
        self.connection.bm.connect("exGameCreated", self.fics_persp.onObserveGameCreated)
Exemple #9
0
    def setUp(self):
        if sys.platform == "win32":
            from asyncio.windows_events import ProactorEventLoop
            loop = ProactorEventLoop()
            asyncio.set_event_loop(loop)
        else:
            loop = asyncio.SelectorEventLoop()
            asyncio.set_event_loop(loop)

        self.loop = asyncio.get_event_loop()
        self.loop.set_debug(enabled=True)

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)
Exemple #10
0
    def test3(self):
        """ Accepting a seek """

        loop = asyncio.get_event_loop()
        loop.set_debug(enabled=True)

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.fics_persp = FICS()
        perspective_manager.add_perspective(self.fics_persp)
        self.fics_persp.create_toolbuttons()

        self.lounge = perspective_manager.get_perspective("fics")
        self.lounge.open_lounge(self.connection, self.connection, "freechess.org")

        lines = [
            "<s> 11 w=WLTL ti=00 rt=2030  t=1 i=0 r=r tp=lightning c=? rr=0-9999 a=t f=f",
            "fics% ",
            BLOCK_START + "52" + BLOCK_SEPARATOR + "158" + BLOCK_SEPARATOR,
            "<sr> 11 16",
            "fics% ",
            "Creating: WLTL (2030) gbtami (1771) rated lightning 1 0",
            "{Game 85 (WLTL vs. gbtami) Creating rated lightning match.}",
            "",
            "<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 85 WLTL gbtami -1 1 0 39 39 60000 60000 1 none (0:00.000) none 1 0 0\n\nGame 85: A disconnection will be considered a forfeit.",
            BLOCK_END,
            "fics% "]

        me = self.connection.players.get('gbtami')
        me.ratings[TYPE_LIGHTNING] = 1771
        opponent = self.connection.players.get('WLTL')
        opponent.ratings[TYPE_LIGHTNING] = 2030
        game = FICSGame(opponent,
                        me,
                        gameno=85,
                        rated=True,
                        game_type=GAME_TYPES['lightning'],
                        private=False,
                        minutes=1,
                        inc=0,
                        board=FICSBoard(60000,
                                        60000,
                                        fen=FEN_START))
        me.game = game
        opponent.game = game
        self.runAndAssertEquals("playGameCreated", lines, (game, ))

        gamemodel = self.games_persp.cur_gmwidg().gamemodel

        def on_game_started(game):
            p1 = gamemodel.players[1]
            p1.move_queue.put_nowait(Move(newMove(G8, F6)))

        gamemodel.connect("game_started", on_game_started)

        lines = [
            "<12> rnbqkbnr pppppppp -------- -------- -------- -P------ P-PPPPPP RNBQKBNR B -1 1 1 1 1 0 85 WLTL gbtami 1 1 0 39 39 60000 60000 1 P/b2-b3 (0:00.000) b3 1 0 0",
            "fics% "]

        game = self.connection.games[game]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        lines = [
            BLOCK_START + "59" + BLOCK_SEPARATOR + "1" + BLOCK_SEPARATOR,
            "<12> rnbqkb-r pppppppp -----n-- -------- -------- -P------ P-PPPPPP RNBQKBNR W -1 1 1 1 1 1 85 WLTL gbtami -1 1 0 39 39 60000 60000 2 N/g8-f6 (0:00.000) Nf6 1 1 0",
            BLOCK_END,
            "fics% ",
            "<12> rnbqkb-r pppppppp -----n-- -------- -------- -P----P- P-PPPP-P RNBQKBNR B -1 1 1 1 1 0 85 WLTL gbtami 1 1 0 39 39 59900 60000 2 P/g2-g3 (0:00.100) g3 1 1 285",
            "fics% "]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)
        self.assertEqual(gamemodel.ply, 3)
        print(gamemodel.boards[-1])
Exemple #11
0
class PlayGameTests(EmittingTestCase):
    def setUp(self):
        EmittingTestCase.setUp(self)
        self.manager = self.connection.bm

    def test1(self):
        """ From gbtami (player accepting a challenge) point of view """
        lines = [
            "Challenge: ggbtami (----) gbtami (1708) unrated blitz 5 0.",
            'You can "accept" or "decline", or propose different parameters.',
            "fics% ",
            "<pf> 7 w=ggbtami t=match p=ggbtami (----) gbtami (1708) unrated blitz 5 0",
            "fics% ", BLOCK_START + '52' + BLOCK_SEPARATOR + '11' +
            BLOCK_SEPARATOR, "You accept the match offer from ggbtami."
            "", "", "<pr> 7", "fics% ",
            "Creating: gbtami (1708) ggbtami (++++) unrated blitz 5 0",
            "{Game 107 (gbtami vs. ggbtami) Creating unrated blitz match.}"
            "", "",
            "<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 107 gbtami ggbtami 1 5 0 39 39 300000 300000 1 none (0:00.000) none 0 0 0",
            ""
            ""
            "Game 107: A disconnection will be considered a forfeit.",
            BLOCK_END, "fics% '"
        ]

        me = self.connection.players.get('gbtami')
        me.ratings[TYPE_BLITZ] = 1708
        opponent = self.connection.players.get('ggbtami')
        opponent.ratings[TYPE_BLITZ] = 0
        game = FICSGame(me,
                        opponent,
                        gameno=107,
                        rated=False,
                        game_type=GAME_TYPES['blitz'],
                        private=False,
                        minutes=5,
                        inc=0,
                        board=FICSBoard(300000, 300000, fen=FEN_START))
        me.game = game
        opponent.game = game
        self.runAndAssertEquals("playGameCreated", lines, (game, ))

        lines = [
            BLOCK_START + '58' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            "<12> rnbqkbnr pppppppp -------- -------- -------- -----P-- PPPPP-PP RNBQKBNR B -1 1 1 1 1 0 107 gbtami ggbtami -1 5 0 39 39 300000 300000 1 P/f2-f3 (0:00.000) f3 0 0 0",
            BLOCK_END, "fics% ",
            "<12> rnbqkbnr pppp-ppp -------- ----p--- -------- -----P-- PPPPP-PP RNBQKBNR W 4 1 1 1 1 0 107 gbtami ggbtami 1 5 0 39 39 300000 300000 2 P/e7-e5 (0:00.000) e5 0 1 0",
            "fics% ",
            BLOCK_START + '61' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            "<12> rnbqkbnr pppp-ppp -------- ----p--- ------P- -----P-- PPPPP--P RNBQKBNR B 6 1 1 1 1 0 107 gbtami ggbtami -1 5 0 39 39 297338 300000 2 P/g2-g4 (0:02.662) g4 0 1 296",
            BLOCK_END, "fics% ",
            "<12> rnb-kbnr pppp-ppp -------- ----p--- ------Pq -----P-- PPPPP--P RNBQKBNR W -1 1 1 1 1 1 107 gbtami ggbtami 1 5 0 39 39 297338 295763 3 Q/d8-h4 (0:04.237) Qh4# 0 1 304",
            "fics% ", "{Game 107 (gbtami vs. ggbtami) gbtami checkmated} 0-1",
            "No ratings adjustment done.", "fics% "
        ]

        game = self.connection.games[game]

        def coro():
            yield from self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 4)
        self.assertEqual(game.reason, WON_MATE)

    def test2(self):
        """ From ggbtami (player sending a challenge) point of view """
        lines = [
            BLOCK_START + '54' + BLOCK_SEPARATOR + '73' + BLOCK_SEPARATOR,
            "Issuing: ggbtami (----) gbtami (1708) unrated blitz 5 0.",
            "<pt> 7 w=gbtami t=match p=ggbtami (----) gbtami (1708) unrated blitz 5 0",
            "fics% ", BLOCK_END, "gbtami accepts the match offer.", "<pr> 7",
            "fics% ",
            "Creating: gbtami (1708) ggbtami (++++) unrated blitz 5 0",
            "{Game 107 (gbtami vs. ggbtami) Creating unrated blitz match.}"
            "", "",
            "<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 107 gbtami ggbtami 1 5 0 39 39 300000 300000 1 none (0:00.000) none 0 0 0",
            ""
            ""
            "Game 107: A disconnection will be considered a forfeit.",
            BLOCK_END, "fics% '"
        ]

        me = self.connection.players.get('gbtami')
        me.ratings[TYPE_BLITZ] = 1708
        opponent = self.connection.players.get('ggbtami')
        opponent.ratings[TYPE_BLITZ] = 0
        game = FICSGame(me,
                        opponent,
                        gameno=107,
                        rated=False,
                        game_type=GAME_TYPES['blitz'],
                        private=False,
                        minutes=5,
                        inc=0,
                        board=FICSBoard(300000, 300000, fen=FEN_START))
        me.game = game
        opponent.game = game
        self.runAndAssertEquals("playGameCreated", lines, (game, ))

        lines = [
            "<12> rnbqkbnr pppppppp -------- -------- -------- -----P-- PPPPP-PP RNBQKBNR B -1 1 1 1 1 0 107 gbtami ggbtami -1 5 0 39 39 300000 300000 1 P/f2-f3 (0:00.000) f3 0 0 0",
            "fics% ",
            BLOCK_START + '61' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            "<12> rnbqkbnr pppp-ppp -------- ----p--- -------- -----P-- PPPPP-PP RNBQKBNR W 4 1 1 1 1 0 107 gbtami ggbtami 1 5 0 39 39 300000 300000 2 P/e7-e5 (0:00.000) e5 0 1 0",
            BLOCK_END, "fics% ",
            "<12> rnbqkbnr pppp-ppp -------- ----p--- ------P- -----P-- PPPPP--P RNBQKBNR B 6 1 1 1 1 0 107 gbtami ggbtami -1 5 0 39 39 297338 300000 2 P/g2-g4 (0:02.662) g4 0 1 296",
            "fics% ",
            BLOCK_START + '64' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            "<12> rnb-kbnr pppp-ppp -------- ----p--- ------Pq -----P-- PPPPP--P RNBQKBNR W -1 1 1 1 1 1 107 gbtami ggbtami 1 5 0 39 39 297338 295763 3 Q/d8-h4 (0:04.237) Qh4# 0 1 304",
            "{Game 107 (gbtami vs. ggbtami) gbtami checkmated} 0-1",
            "No ratings adjustment done.", BLOCK_END, "fics% "
        ]

        game = self.connection.games[game]

        def coro():
            yield from self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 4)
        self.assertEqual(game.reason, WON_MATE)

    def test3(self):
        """ Accepting a seek """

        loop = asyncio.get_event_loop()
        loop.set_debug(enabled=True)

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.fics_persp = FICS()
        perspective_manager.add_perspective(self.fics_persp)
        self.fics_persp.create_toolbuttons()

        self.lounge = perspective_manager.get_perspective("fics")
        self.lounge.open_lounge(self.connection, self.connection,
                                "freechess.org")

        lines = [
            "<s> 11 w=WLTL ti=00 rt=2030  t=1 i=0 r=r tp=lightning c=? rr=0-9999 a=t f=f",
            "fics% ",
            BLOCK_START + "52" + BLOCK_SEPARATOR + "158" + BLOCK_SEPARATOR,
            "<sr> 11 16", "fics% ",
            "Creating: WLTL (2030) gbtami (1771) rated lightning 1 0",
            "{Game 85 (WLTL vs. gbtami) Creating rated lightning match.}", "",
            "<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 85 WLTL gbtami -1 1 0 39 39 60000 60000 1 none (0:00.000) none 1 0 0\n\nGame 85: A disconnection will be considered a forfeit.",
            BLOCK_END, "fics% "
        ]

        me = self.connection.players.get('gbtami')
        me.ratings[TYPE_LIGHTNING] = 1771
        opponent = self.connection.players.get('WLTL')
        opponent.ratings[TYPE_LIGHTNING] = 2030
        game = FICSGame(opponent,
                        me,
                        gameno=85,
                        rated=True,
                        game_type=GAME_TYPES['lightning'],
                        private=False,
                        minutes=1,
                        inc=0,
                        board=FICSBoard(60000, 60000, fen=FEN_START))
        me.game = game
        opponent.game = game
        self.runAndAssertEquals("playGameCreated", lines, (game, ))

        gamemodel = self.games_persp.cur_gmwidg().gamemodel

        def on_game_started(game):
            p1 = gamemodel.players[1]
            p1.move_queue.put_nowait(Move(newMove(G8, F6)))

        gamemodel.connect("game_started", on_game_started)

        lines = [
            "<12> rnbqkbnr pppppppp -------- -------- -------- -P------ P-PPPPPP RNBQKBNR B -1 1 1 1 1 0 85 WLTL gbtami 1 1 0 39 39 60000 60000 1 P/b2-b3 (0:00.000) b3 1 0 0",
            "fics% "
        ]

        game = self.connection.games[game]

        def coro():
            yield from self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        lines = [
            BLOCK_START + "59" + BLOCK_SEPARATOR + "1" + BLOCK_SEPARATOR,
            "<12> rnbqkb-r pppppppp -----n-- -------- -------- -P------ P-PPPPPP RNBQKBNR W -1 1 1 1 1 1 85 WLTL gbtami -1 1 0 39 39 60000 60000 2 N/g8-f6 (0:00.000) Nf6 1 1 0",
            BLOCK_END, "fics% ",
            "<12> rnbqkb-r pppppppp -----n-- -------- -------- -P----P- P-PPPP-P RNBQKBNR B -1 1 1 1 1 0 85 WLTL gbtami 1 1 0 39 39 59900 60000 2 P/g2-g3 (0:00.100) g3 1 1 285",
            "fics% "
        ]

        def coro():
            yield from self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)
        self.assertEqual(gamemodel.ply, 3)
        print(gamemodel.boards[-1])
Exemple #12
0
class ExamineGameTests(EmittingTestCase):
    def setUp(self):
        EmittingTestCase.setUp(self)
        self.loop.set_debug(enabled=True)

        self.manager = self.connection.bm

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.fics_persp = FICS()
        perspective_manager.add_perspective(self.fics_persp)

        self.fics_persp.connection = self.connection
        self.connection.bm.connect("obsGameCreated", self.fics_persp.onObserveGameCreated)
        self.connection.bm.connect("exGameCreated", self.fics_persp.onObserveGameCreated)

    def test1(self):
        """ Test puzzlebot starting a new mate in 2 puzzle """

        # tell puzzlebot gm2
        lines = [
            BLOCK_START + '92' + BLOCK_SEPARATOR + '132' + BLOCK_SEPARATOR,
            '(told puzzlebot, who is examining a game)',
            BLOCK_END,
            'fics% ',
            BLOCK_POSE_START + '\n' + BLOCK_START + '0' + BLOCK_SEPARATOR + '80' + BLOCK_SEPARATOR,
            'You are now observing game 127.',
            'Game 127: gbtami (0) puzzlebot (0) unrated untimed 0 0',
            '',
            '<12> --kr---r pp--bppp ----bn-- -Npp---q -----B-Q ---B---- PPP--PPP -K-R---R W -1 0 0 0 0 0 127 gbtami puzzlebot -2 0 0 0 0 0 0 1 none (0:00.000) none 0 0 0',
            BLOCK_END, 'fics% ', BLOCK_POSE_END,
        ]

        signal = 'obsGameCreated'

        game = FICSGame(
            FICSPlayer("gbtami"),
            FICSPlayer("puzzlebot"),
            gameno=127,
            relation=IC_POS_OBSERVING_EXAMINATION)
        game = self.connection.games.get(game)
        expectedResults = (game, )
        self.runAndAssertEquals(signal, lines, expectedResults)

        print(self.games_persp.cur_gmwidg().gamemodel)

        lines = [
            'Removing game 127 from observation list.'
            '',
            'puzzlebot has made you an examiner of game 127.',
            '',
            '<12> --kr---r pp--bppp ----bn-- -Npp---q -----B-Q ---B---- PPP--PPP -K-R---R W -1 0 0 0 0 0 127 gbtami puzzlebot 2 0 0 0 0 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: This is mate problem number [00655]',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: White moves and mates in 2 moves.',
            'fics% ',
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        # check that our relation has changed as expected
        self.assertEqual(game.relation, IC_POS_EXAMINATING)

        # try with a wrong move first: h4h5
        lines = [
            'puzzlebot stopped examining game 127.',
            'fics% ',
            BLOCK_START + '109' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> --kr---r pp--bppp ----bn-- -Npp---Q -----B-- ---B---- PPP--PPP -K-R---R B -1 0 0 0 0 0 127 gbtami puzzlebot 2 0 0 0 247 0 0 1 Q/h4-h5 (0:00.000) Qxh5 0 0 0',
            '',
            'Game 127: gbtami moves: Qxh5',
            BLOCK_END,
            'fics% ',
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        game = self.connection.games.get(game)
        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 1)

        # puzzlebot just backs up our move and sends the puzzle starting position again
        lines = [
            BLOCK_POSE_START + '\n' + BLOCK_START + '0' + BLOCK_SEPARATOR + '80' + BLOCK_SEPARATOR,
            'puzzlebot is now an examiner of game 127.',
            BLOCK_END, 'fics% ', BLOCK_POSE_END,
            'Game 127: puzzlebot backs up 1 move.',
            '',
            '<12> --kr---r pp--bppp ----bn-- -Npp---q -----B-Q ---B---- PPP--PPP -K-R---R W -1 0 0 0 0 0 127 gbtami puzzlebot 2 0 0 34 35 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            'Game 127: Still in progress *',
            '',
            'puzzlebot(TD)(----)[127] kibitzes: There is a better move.',
            'fics% ',
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 0)

        # now we take the good move: b5a7
        lines = [
            'puzzlebot stopped examining game 127.',
            'fics% ',
            BLOCK_START + '114' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> --kr---r Np--bppp ----bn-- --pp---q -----B-Q ---B---- PPP--PPP -K-R---R B -1 0 0 0 0 0 127 gbtami puzzlebot 2 0 0 34 34 0 0 1 N/b5-a7 (0:00.000) Nxa7+ 0 0 0',
            '',
            'Game 127: gbtami moves: Nxa7+',
            BLOCK_END,
            'fics% ',
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 1)

        # puzzlebot moves
        lines = [
            BLOCK_POSE_START + '\n' + BLOCK_START + '0' + BLOCK_SEPARATOR + '75' + BLOCK_SEPARATOR,
            'puzzlebot is now an examiner of game 127.',
            BLOCK_END, 'fics% ', BLOCK_POSE_END,
            '<12> ---r---r Np-kbppp ----bn-- --pp---q -----B-Q ---B---- PPP--PPP -K-R---R W -1 0 0 0 0 1 127 gbtami puzzlebot 2 0 0 34 34 0 0 2 K/c8-d7 (0:00.000) Kd7 0 0 0',
            'fics% ',
            'Game 127: puzzlebot moves: Kd7',
            'fics% '
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])
        print(self.games_persp.cur_gmwidg().gamemodel.moves)

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 2)

        # we make the mating move: d3b5
        lines = [
            'puzzlebot stopped examining game 127.',
            'fics% ',
            BLOCK_START + '117' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> ---r---r Np-kbppp ----bn-- -Bpp---q -----B-Q -------- PPP--PPP -K-R---R B -1 0 0 0 0 2 127 gbtami puzzlebot 2 0 0 34 34 0 0 2 B/d3-b5 (0:00.000) Bb5# 0 0 0',
            ''
            'Game 127: gbtami moves: Bb5#',
            '',
            'Game 127: Black checkmated 1-0',
            BLOCK_END,
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: You solved problem number [00655] in 02m01s',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: You made 1 wrong moves and needed 0 hints',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: To solve the next problem type "tell puzzlebot next". To solve the previous problem type "tell puzzlebot previous" To automatically load problems type "tell puzzlebot auto" Or type "tell puzzlebot getmate" or "tell puzzlebot gettactics" or "tell puzzlebot getstudy"',
            'fics% ',
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 3)

        ########################################################################
        # now start another mate in 2 puzzle
        # tell puzzlebot next
        lines = [
            BLOCK_START + '125' + BLOCK_SEPARATOR + '132' + BLOCK_SEPARATOR,
            '(told puzzlebot, who is examining a game)',
            BLOCK_END,
            'fics% ',
            BLOCK_POSE_START + '\n' + BLOCK_START + '0' + BLOCK_SEPARATOR + '80' + BLOCK_SEPARATOR,
            'You are now observing game 127.',
            'Game 127: gbtami (0) puzzlebot (0) unrated untimed 0 0',
            '',
            '<12> -----k-- -R------ --p--n-- -------- P-P--pr- -P---RNK -----PP- ----r--- B -1 0 0 0 0 0 127 puzzlebot gbtami -2 0 0 0 0 0 0 1 none (0:00.000) none 0 0 0',
        ]

        signal = 'obsGameCreated'

        game = FICSGame(
            FICSPlayer("puzzlebot"),
            FICSPlayer("gbtami"),
            gameno=127,
            relation=IC_POS_OBSERVING_EXAMINATION)
        game = self.connection.games.get(game)
        expectedResults = (game, )
        self.runAndAssertEquals(signal, lines, expectedResults)

        print(self.games_persp.cur_gmwidg().gamemodel)

        lines = [
            'Removing game 127 from observation list.'
            '',
            'puzzlebot has made you an examiner of game 127.',
            '',
            '<12> -----k-- -R------ --p--n-- -------- P-P--pr- -P---RNK -----PP- ----r--- B -1 0 0 0 0 0 127 puzzlebot gbtami 2 0 0 0 0 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: This is mate problem number [00656]',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: Black moves and mates in 2 moves.',
            'fics% ',
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        # check that our relation has changed as expected
        self.assertEqual(game.relation, IC_POS_EXAMINATING)

        # g4g3
        lines = [
            'puzzlebot stopped examining game 127.',
            'fics% ',
            BLOCK_START + '147' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> -----k-- -R------ --p--n-- -------- P-P--p-- -P---RrK -----PP- ----r--- W -1 0 0 0 0 0 127 puzzlebot gbtami 2 0 0 253 0 0 0 2 R/g4-g3 (0:00.000) Rxg3+ 0 0 0',
            '',
            'Game 127: gbtami moves: Rxg3+',
            BLOCK_END,
            'fics% ',
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 2)

        # puzzlebot moves
        lines = [
            BLOCK_POSE_START + '\n' + BLOCK_START + '0' + BLOCK_SEPARATOR + '75' + BLOCK_SEPARATOR,
            'puzzlebot is now an examiner of game 127.',
            BLOCK_END, 'fics% ', BLOCK_POSE_END,
            'fics% ',
            '<12> -----k-- -R------ --p--n-- -------- P-P--p-- -P---RPK ------P- ----r--- B -1 0 0 0 0 0 127 puzzlebot gbtami 2 0 0 253 251 0 0 2 P/f2-g3 (0:00.000) fxg3 0 0 0',
            'Game 127: puzzlebot moves: fxg3',
            'fics% '
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 3)

        # we make the mating move: e1h1
        lines = [
            'puzzlebot stopped examining game 127.',
            'fics% ',
            BLOCK_START + '150' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> -----k-- -R------ --p--n-- -------- P-P--p-- -P---RPK ------P- -------r W -1 0 0 0 0 1 127 puzzlebot gbtami 2 0 0 253 251 0 0 3 R/e1-h1 (0:00.000) Rh1# 0 0 0',
            ''
            'Game 127: gbtami moves: Rh1#',
            '',
            'Game 127: White checkmated 0-1',
            BLOCK_END,
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: You solved problem number [00656] in 00m45s',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: You made 1 wrong moves and needed 0 hints',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: To solve the next problem type "tell puzzlebot next". To solve the previous problem type "tell puzzlebot previous" To automatically load problems type "tell puzzlebot auto" Or type "tell puzzlebot getmate" or "tell puzzlebot gettactics" or "tell puzzlebot getstudy"',
            'fics% ',
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 4)
Exemple #13
0
class ExamineGameTests(EmittingTestCase):
    def setUp(self):
        EmittingTestCase.setUp(self)
        self.loop.set_debug(enabled=True)

        self.manager = self.connection.bm

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.fics_persp = FICS()
        perspective_manager.add_perspective(self.fics_persp)

        self.fics_persp.connection = self.connection
        self.connection.bm.connect("obsGameCreated",
                                   self.fics_persp.onObserveGameCreated)
        self.connection.bm.connect("exGameCreated",
                                   self.fics_persp.onObserveGameCreated)

    def test1(self):
        """ Test puzzlebot starting a new mate in 2 puzzle """

        # tell puzzlebot gm2
        lines = [
            BLOCK_START + '92' + BLOCK_SEPARATOR + '132' + BLOCK_SEPARATOR,
            '(told puzzlebot, who is examining a game)',
            BLOCK_END,
            'fics% ',
            BLOCK_POSE_START + '\n' + BLOCK_START + '0' + BLOCK_SEPARATOR +
            '80' + BLOCK_SEPARATOR,
            'You are now observing game 127.',
            'Game 127: gbtami (0) puzzlebot (0) unrated untimed 0 0',
            '',
            '<12> --kr---r pp--bppp ----bn-- -Npp---q -----B-Q ---B---- PPP--PPP -K-R---R W -1 0 0 0 0 0 127 gbtami puzzlebot -2 0 0 0 0 0 0 1 none (0:00.000) none 0 0 0',
            BLOCK_END,
            'fics% ',
            BLOCK_POSE_END,
        ]

        signal = 'obsGameCreated'

        game = FICSGame(FICSPlayer("gbtami"),
                        FICSPlayer("puzzlebot"),
                        gameno=127,
                        relation=IC_POS_OBSERVING_EXAMINATION)
        game = self.connection.games.get(game)
        expectedResults = (game, )
        self.runAndAssertEquals(signal, lines, expectedResults)

        print(self.games_persp.cur_gmwidg().gamemodel)

        lines = [
            'Removing game 127 from observation list.'
            '',
            'puzzlebot has made you an examiner of game 127.',
            '',
            '<12> --kr---r pp--bppp ----bn-- -Npp---q -----B-Q ---B---- PPP--PPP -K-R---R W -1 0 0 0 0 0 127 gbtami puzzlebot 2 0 0 0 0 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: This is mate problem number [00655]',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: White moves and mates in 2 moves.',
            'fics% ',
        ]

        async def coro():
            await self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        # check that our relation has changed as expected
        self.assertEqual(game.relation, IC_POS_EXAMINATING)

        # try with a wrong move first: h4h5
        lines = [
            'puzzlebot stopped examining game 127.',
            'fics% ',
            BLOCK_START + '109' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> --kr---r pp--bppp ----bn-- -Npp---Q -----B-- ---B---- PPP--PPP -K-R---R B -1 0 0 0 0 0 127 gbtami puzzlebot 2 0 0 0 247 0 0 1 Q/h4-h5 (0:00.000) Qxh5 0 0 0',
            '',
            'Game 127: gbtami moves: Qxh5',
            BLOCK_END,
            'fics% ',
        ]

        async def coro():
            await self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        game = self.connection.games.get(game)
        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 1)

        # puzzlebot just backs up our move and sends the puzzle starting position again
        lines = [
            BLOCK_POSE_START + '\n' + BLOCK_START + '0' + BLOCK_SEPARATOR +
            '80' + BLOCK_SEPARATOR,
            'puzzlebot is now an examiner of game 127.',
            BLOCK_END,
            'fics% ',
            BLOCK_POSE_END,
            'Game 127: puzzlebot backs up 1 move.',
            '',
            '<12> --kr---r pp--bppp ----bn-- -Npp---q -----B-Q ---B---- PPP--PPP -K-R---R W -1 0 0 0 0 0 127 gbtami puzzlebot 2 0 0 34 35 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            'Game 127: Still in progress *',
            '',
            'puzzlebot(TD)(----)[127] kibitzes: There is a better move.',
            'fics% ',
        ]

        async def coro():
            await self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 0)

        # now we take the good move: b5a7
        lines = [
            'puzzlebot stopped examining game 127.',
            'fics% ',
            BLOCK_START + '114' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> --kr---r Np--bppp ----bn-- --pp---q -----B-Q ---B---- PPP--PPP -K-R---R B -1 0 0 0 0 0 127 gbtami puzzlebot 2 0 0 34 34 0 0 1 N/b5-a7 (0:00.000) Nxa7+ 0 0 0',
            '',
            'Game 127: gbtami moves: Nxa7+',
            BLOCK_END,
            'fics% ',
        ]

        async def coro():
            await self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 1)

        # puzzlebot moves
        lines = [
            BLOCK_POSE_START + '\n' + BLOCK_START + '0' + BLOCK_SEPARATOR +
            '75' + BLOCK_SEPARATOR,
            'puzzlebot is now an examiner of game 127.', BLOCK_END, 'fics% ',
            BLOCK_POSE_END,
            '<12> ---r---r Np-kbppp ----bn-- --pp---q -----B-Q ---B---- PPP--PPP -K-R---R W -1 0 0 0 0 1 127 gbtami puzzlebot 2 0 0 34 34 0 0 2 K/c8-d7 (0:00.000) Kd7 0 0 0',
            'fics% ', 'Game 127: puzzlebot moves: Kd7', 'fics% '
        ]

        async def coro():
            await self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])
        print(self.games_persp.cur_gmwidg().gamemodel.moves)

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 2)

        # we make the mating move: d3b5
        lines = [
            'puzzlebot stopped examining game 127.',
            'fics% ',
            BLOCK_START + '117' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> ---r---r Np-kbppp ----bn-- -Bpp---q -----B-Q -------- PPP--PPP -K-R---R B -1 0 0 0 0 2 127 gbtami puzzlebot 2 0 0 34 34 0 0 2 B/d3-b5 (0:00.000) Bb5# 0 0 0',
            ''
            'Game 127: gbtami moves: Bb5#',
            '',
            'Game 127: Black checkmated 1-0',
            BLOCK_END,
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: You solved problem number [00655] in 02m01s',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: You made 1 wrong moves and needed 0 hints',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: To solve the next problem type "tell puzzlebot next". To solve the previous problem type "tell puzzlebot previous" To automatically load problems type "tell puzzlebot auto" Or type "tell puzzlebot getmate" or "tell puzzlebot gettactics" or "tell puzzlebot getstudy"',
            'fics% ',
        ]

        async def coro():
            await self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 3)

        ########################################################################
        # now start another mate in 2 puzzle
        # tell puzzlebot next
        lines = [
            BLOCK_START + '125' + BLOCK_SEPARATOR + '132' + BLOCK_SEPARATOR,
            '(told puzzlebot, who is examining a game)',
            BLOCK_END,
            'fics% ',
            BLOCK_POSE_START + '\n' + BLOCK_START + '0' + BLOCK_SEPARATOR +
            '80' + BLOCK_SEPARATOR,
            'You are now observing game 127.',
            'Game 127: gbtami (0) puzzlebot (0) unrated untimed 0 0',
            '',
            '<12> -----k-- -R------ --p--n-- -------- P-P--pr- -P---RNK -----PP- ----r--- B -1 0 0 0 0 0 127 puzzlebot gbtami -2 0 0 0 0 0 0 1 none (0:00.000) none 0 0 0',
        ]

        signal = 'obsGameCreated'

        game = FICSGame(FICSPlayer("puzzlebot"),
                        FICSPlayer("gbtami"),
                        gameno=127,
                        relation=IC_POS_OBSERVING_EXAMINATION)
        game = self.connection.games.get(game)
        expectedResults = (game, )
        self.runAndAssertEquals(signal, lines, expectedResults)

        print(self.games_persp.cur_gmwidg().gamemodel)

        lines = [
            'Removing game 127 from observation list.'
            '',
            'puzzlebot has made you an examiner of game 127.',
            '',
            '<12> -----k-- -R------ --p--n-- -------- P-P--pr- -P---RNK -----PP- ----r--- B -1 0 0 0 0 0 127 puzzlebot gbtami 2 0 0 0 0 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: This is mate problem number [00656]',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: Black moves and mates in 2 moves.',
            'fics% ',
        ]

        async def coro():
            await self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        # check that our relation has changed as expected
        self.assertEqual(game.relation, IC_POS_EXAMINATING)

        # g4g3
        lines = [
            'puzzlebot stopped examining game 127.',
            'fics% ',
            BLOCK_START + '147' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> -----k-- -R------ --p--n-- -------- P-P--p-- -P---RrK -----PP- ----r--- W -1 0 0 0 0 0 127 puzzlebot gbtami 2 0 0 253 0 0 0 2 R/g4-g3 (0:00.000) Rxg3+ 0 0 0',
            '',
            'Game 127: gbtami moves: Rxg3+',
            BLOCK_END,
            'fics% ',
        ]

        async def coro():
            await self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 2)

        # puzzlebot moves
        lines = [
            BLOCK_POSE_START + '\n' + BLOCK_START + '0' + BLOCK_SEPARATOR +
            '75' + BLOCK_SEPARATOR,
            'puzzlebot is now an examiner of game 127.', BLOCK_END, 'fics% ',
            BLOCK_POSE_END, 'fics% ',
            '<12> -----k-- -R------ --p--n-- -------- P-P--p-- -P---RPK ------P- ----r--- B -1 0 0 0 0 0 127 puzzlebot gbtami 2 0 0 253 251 0 0 2 P/f2-g3 (0:00.000) fxg3 0 0 0',
            'Game 127: puzzlebot moves: fxg3', 'fics% '
        ]

        async def coro():
            await self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 3)

        # we make the mating move: e1h1
        lines = [
            'puzzlebot stopped examining game 127.',
            'fics% ',
            BLOCK_START + '150' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> -----k-- -R------ --p--n-- -------- P-P--p-- -P---RPK ------P- -------r W -1 0 0 0 0 1 127 puzzlebot gbtami 2 0 0 253 251 0 0 3 R/e1-h1 (0:00.000) Rh1# 0 0 0',
            ''
            'Game 127: gbtami moves: Rh1#',
            '',
            'Game 127: White checkmated 0-1',
            BLOCK_END,
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: You solved problem number [00656] in 00m45s',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: You made 1 wrong moves and needed 0 hints',
            'fics% ',
            'puzzlebot(TD)(----)[127] kibitzes: To solve the next problem type "tell puzzlebot next". To solve the previous problem type "tell puzzlebot previous" To automatically load problems type "tell puzzlebot auto" Or type "tell puzzlebot getmate" or "tell puzzlebot gettactics" or "tell puzzlebot getstudy"',
            'fics% ',
        ]

        async def coro():
            await self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 4)
Exemple #14
0
    def test3(self):
        """ Accepting a seek """

        loop = asyncio.get_event_loop()
        loop.set_debug(enabled=True)

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.fics_persp = FICS()
        perspective_manager.add_perspective(self.fics_persp)
        self.fics_persp.create_toolbuttons()

        self.lounge = perspective_manager.get_perspective("fics")
        self.lounge.open_lounge(self.connection, self.connection,
                                "freechess.org")

        lines = [
            "<s> 11 w=WLTL ti=00 rt=2030  t=1 i=0 r=r tp=lightning c=? rr=0-9999 a=t f=f",
            "fics% ",
            BLOCK_START + "52" + BLOCK_SEPARATOR + "158" + BLOCK_SEPARATOR,
            "<sr> 11 16", "fics% ",
            "Creating: WLTL (2030) gbtami (1771) rated lightning 1 0",
            "{Game 85 (WLTL vs. gbtami) Creating rated lightning match.}", "",
            "<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 85 WLTL gbtami -1 1 0 39 39 60000 60000 1 none (0:00.000) none 1 0 0\n\nGame 85: A disconnection will be considered a forfeit.",
            BLOCK_END, "fics% "
        ]

        me = self.connection.players.get('gbtami')
        me.ratings[TYPE_LIGHTNING] = 1771
        opponent = self.connection.players.get('WLTL')
        opponent.ratings[TYPE_LIGHTNING] = 2030
        game = FICSGame(opponent,
                        me,
                        gameno=85,
                        rated=True,
                        game_type=GAME_TYPES['lightning'],
                        private=False,
                        minutes=1,
                        inc=0,
                        board=FICSBoard(60000, 60000, fen=FEN_START))
        me.game = game
        opponent.game = game
        self.runAndAssertEquals("playGameCreated", lines, (game, ))

        gamemodel = self.games_persp.cur_gmwidg().gamemodel

        def on_game_started(game):
            p1 = gamemodel.players[1]
            p1.move_queue.put_nowait(Move(newMove(G8, F6)))

        gamemodel.connect("game_started", on_game_started)

        lines = [
            "<12> rnbqkbnr pppppppp -------- -------- -------- -P------ P-PPPPPP RNBQKBNR B -1 1 1 1 1 0 85 WLTL gbtami 1 1 0 39 39 60000 60000 1 P/b2-b3 (0:00.000) b3 1 0 0",
            "fics% "
        ]

        game = self.connection.games[game]

        def coro():
            yield from self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        lines = [
            BLOCK_START + "59" + BLOCK_SEPARATOR + "1" + BLOCK_SEPARATOR,
            "<12> rnbqkb-r pppppppp -----n-- -------- -------- -P------ P-PPPPPP RNBQKBNR W -1 1 1 1 1 1 85 WLTL gbtami -1 1 0 39 39 60000 60000 2 N/g8-f6 (0:00.000) Nf6 1 1 0",
            BLOCK_END, "fics% ",
            "<12> rnbqkb-r pppppppp -----n-- -------- -------- -P----P- P-PPPP-P RNBQKBNR B -1 1 1 1 1 0 85 WLTL gbtami 1 1 0 39 39 59900 60000 2 P/g2-g3 (0:00.100) g3 1 1 285",
            "fics% "
        ]

        def coro():
            yield from self.connection.process_lines(lines)

        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)
        self.assertEqual(gamemodel.ply, 3)
        print(gamemodel.boards[-1])
Exemple #15
0
class ObserveGameTests(EmittingTestCase):
    def setUp(self):
        EmittingTestCase.setUp(self)
        self.manager = self.connection.bm

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.fics_persp = FICS()
        perspective_manager.add_perspective(self.fics_persp)

        self.fics_persp.connection = self.connection
        self.connection.bm.connect("obsGameCreated", self.fics_persp.onObserveGameCreated)

    def test1(self):
        """ Test observing game """

        lines = [
            "{Game 463 (schachbjm vs. Maras) Creating rated standard match.}",
            BLOCK_START + '34' + BLOCK_SEPARATOR + '80' + BLOCK_SEPARATOR,
            'You are now observing game 463.',
            'Game 463: schachbjm (2243) Maras (2158E) rated standard 45 45',
            '',
            '<12> -r------ --k----- ----p--- n-ppPb-p -----P-P -PP-K-P- PR------ --R----- W -1 0 0 0 0 11 463 schachbjm Maras 0 45 45 17 15 557871 274070 37 R/f8-b8 (0:10.025) Rb8 0 1 0',
            BLOCK_END
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(self.connection.client.commands[-1], "moves 463")

        signal = 'obsGameCreated'
        lines = [
            'Movelist for game 463:',
            '',
            'schachbjm (2243) vs. Maras (2158) --- Sat Jan 23, 14:34 EST 2016',
            'Rated standard match, initial time: 45 minutes, increment: 45 seconds.',
            '',
            'Move  schachbjm               Maras',
            '----  ---------------------   ---------------------',
            '1.  e4      (0:00.000)      e6      (0:00.000)',
            '2.  d4      (0:01.617)      d5      (0:02.220)',
            '3.  Nc3     (0:00.442)      Nc6     (0:54.807)',
            '4.  e5      (0:40.427)      Nge7    (0:28.205)',
            '5.  Nf3     (0:21.570)      Nf5     (0:28.818)',
            '6.  h4      (1:17.369)      h5      (4:58.315)',
            '7.  Bg5     (0:55.946)      Be7     (4:01.555)',
            '8.  Qd2     (0:02.434)      b6      (5:12.110)',
            '9.  O-O-O   (0:59.124)      Bb7     (0:08.796)',
            '10.  Kb1     (0:01.900)      Qd7     (4:39.500)',
            '11.  Bxe7    (19:59.514)     Qxe7    (2:42.462)',
            '12.  g3      (0:58.847)      O-O-O   (0:36.468)',
            '13.  Bh3     (0:12.284)      Nh6     (4:06.076)',
            '14.  Ne2     (0:02.387)      g6      (5:02.695)',
            '15.  Nf4     (0:02.976)      Kb8     (5:26.776)',
            '16.  Rhe1    (2:33.781)      Na5     (2:23.956)',
            '17.  b3      (0:28.817)      Rc8     (1:09.281)',
            '18.  Ng5     (8:15.515)      c5      (5:17.139)',
            '19.  Bxe6    (12:26.052)     fxe6    (1:14.670)',
            '20.  Nxg6    (0:02.168)      Qd7     (1:23.832)',
            '21.  Nxh8    (0:02.249)      Rxh8    (0:04.212)',
            '22.  dxc5    (0:14.456)      Nf5     (0:24.046)',
            '23.  cxb6    (0:07.092)      axb6    (0:03.296)',
            '24.  Qb4     (0:42.800)      Qc6     (2:48.991)',
            '25.  Nf7     (2:09.657)      Rc8     (0:37.030)',
            '26.  Rd2     (0:01.602)      Qc5     (5:03.082)',
            '27.  Qxc5    (0:09.672)      bxc5    (0:00.100)',
            '28.  Nd6     (0:00.849)      Rf8     (0:04.101)',
            '29.  c3      (0:57.437)      Kc7     (3:05.263)',
            '30.  Nxf5    (1:51.872)      Rxf5    (0:00.100)',
            '31.  f4      (0:00.603)      Bc6     (1:06.696)',
            '32.  Kc2     (0:01.613)      Be8     (0:07.670)',
            '33.  Kd3     (1:39.823)      Rf8     (1:28.227)',
            '34.  Ke3     (0:06.207)      Bg6     (0:08.648)',
            '35.  Rc1     (3:24.100)      Bf5     (1:11.762)',
            '36.  Rb2     (0:13.173)      Rb8     (0:10.025)',
            '{Still in progress} *',
        ]

        game = FICSGame(
            FICSPlayer("schachbjm"),
            FICSPlayer("Maras"),
            gameno=463)
        game = self.connection.games.get(game)
        expectedResults = (game, )
        self.runAndAssertEquals(signal, lines, expectedResults)

        print(self.games_persp.cur_gmwidg().gamemodel)

        lines = [
            '<12> -r------ --k----- ----p--- n-ppPb-p -----P-P -PP-K-P- PR------ ------R- B -1 0 0 0 0 11 463 schachbjm Maras 0 45 45 17 15 557871 274070 37 R/b2-g2 (0:10.025) Rg2 0 1 0',
            '<12> ------r- --k----- ----p--- n-ppPb-p -----P-P -PP-K-P- PR------ ------R- W -1 0 0 0 0 11 463 schachbjm Maras 0 45 45 17 15 557871 274070 38 R/b8-g8 (0:10.025) Rg8 0 1 0',
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 74)

        print(self.games_persp.cur_gmwidg().gamemodel)

    def test2(self):
        """ Test observing lecturebot """

        # ♜ ♛ . . ♚ . ♞ ♜
        # ♟ ♟ . ♝ . ♟ ♟ ♟
        # . . . ♝ ♟ . . .
        # . . . ♘ . . . .
        # . . . . . . ♕ .
        # . . . ♗ . . . .
        # ♙ ♙ . . . ♙ ♙ .
        # ♖ . ♗ . ♖ . . ♔

        lines = [
            BLOCK_START + '53' + BLOCK_SEPARATOR + '80' + BLOCK_SEPARATOR,
            'You are now observing game 1.',
            'Game 1: LectureBot (0) LectureBot (0) unrated untimed 0 0',
            '',
            '<12> rq--k-nr pp-b-ppp ---bp--- ---N---- ------Q- ---B---- PP---PP- R-B-R--K W -1 0 0 1 1 2 1 LectureBot LectureBot -2 0 0 32 34 0 0 15 B/h2-d6 (0:00.000) Bd6 0 0 0',
            BLOCK_END
        ]

        signal = 'obsGameCreated'

        game = FICSGame(
            FICSPlayer("LectureBot"),
            FICSPlayer("LectureBot"),
            gameno=1)
        game = self.connection.games.get(game)
        expectedResults = (game, )
        self.runAndAssertEquals(signal, lines, expectedResults)

        print(self.games_persp.cur_gmwidg().gamemodel)

        lines = [
            "<12> rq--k-nr pp-b-pQp ---bp--- ---N---- -------- ---B---- PP---PP- R-B-R--K B -1 0 0 1 1 0 1 LectureBot LectureBot -2 0 0 32 33 0 0 15 Q/g4-g7 (0:00.000) Qxg7 0 0 0",
            "fics% ",
            "Game 1: LectureBot moves: Qxg7",
            "nfics% ",
            "LectureBot(TD)(----)[1] kibitzes: Black is now going to drop a rook.  Therefore, Black must find an alternate to 13...Bxh2+.",
            "fics% ",
            "LectureBot(TD)(----)[1] kibitzes: Let\'s back up and find the right 13th move.",
            "fics% "
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 29)

        print(self.games_persp.cur_gmwidg().gamemodel)

        lines = [
            "Game 1: LectureBot backs up 4 moves.",
            "<12> rq--k-nr pp-b-ppp ---bp--- ---N---- ------Q- ---B---- PP---PPP R-B-R-K- B -1 0 0 1 1 2 1 LectureBot LectureBot -2 0 0 33 34 0 0 13 Q/d1-g4 (0:00.000) Qg4 0 0 0",
            "fics% ",
            "LectureBot(TD)(----)[1] kibitzes: Can you find Black\'s best move?",
            "fics% "
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 25)

        print(self.games_persp.cur_gmwidg().gamemodel)

        lines = [
            "<12> rq---knr pp-b-ppp ---bp--- ---N---- ------Q- ---B---- PP---PPP R-B-R-K- W -1 0 0 0 0 3 1 LectureBot LectureBot -2 0 0 33 34 0 0 14 K/e8-f8 (0:00.000) Kf8 0 0 0",
            "fics% ",
            "Game 1: LectureBot moves: Kf8",
            "fics% ",
            "LectureBot(TD)(----)[1] kibitzes: Black needs to guard the g-pawn.  This also gets the king out of the pin.",
            "fics% ",
            "<12> rq---knr pp-b-ppp ---bp--- ---N---- ------Q- ---B---- PP-B-PPP R---R-K- B -1 0 0 0 0 4 1 LectureBot LectureBot -2 0 0 33 34 0 0 14 B/c1-d2 (0:00.000) Bd2 0 0 0",
            "fics% ",
            "Game 1: LectureBot moves: Bd2",
            "fics% ",
            "LectureBot(TD)(----)[1] kibitzes: White doesn\'t have to move the attacked knight because if 14. exd5, 15. Qxd7 is a trade.",
            "fics% ",
            "LectureBot(TD)(----)[1] kibitzes: Not to mention, it would be a trade favorable to White.",
            "fics% ",
            "<12> rq---knr pp-b-pp- ---bp--- ---N---p ------Q- ---B---- PP-B-PPP R---R-K- W 7 0 0 0 0 0 1 LectureBot LectureBot -2 0 0 33 34 0 0 15 P/h7-h5 (0:00.000) h5 0 0 0",
            "fics% ",
            "Game 1: LectureBot moves: h5",
            "fics% ",
            "LectureBot(TD)(----)[1] kibitzes: Here, Black attacks White\'s queen, and will try to open the h-file for his rook.",
            "fics% "
        ]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 28)

        print(self.games_persp.cur_gmwidg().gamemodel)
Exemple #16
0
class DatabaseTests(unittest.TestCase):
    def setUp(self):
        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.database_persp = Database()
        perspective_manager.add_perspective(self.database_persp)
        self.database_persp.create_toolbuttons()

    def test1(self):
        """ Play and save Human-Human 1 min game """

        loop = asyncio.get_event_loop()
        loop.set_debug(enabled=True)

        def coro():
            gamemodel = GameModel(TimeModel(1, 0))

            player0tup = (LOCAL, Human, (WHITE, "w"), "w")
            player1tup = (LOCAL, Human, (BLACK, "b"), "b")

            def on_game_end(game, state, event):
                event.set()

            event = asyncio.Event()
            gamemodel.connect("game_ended", on_game_end, event)

            def on_players_changed(game):
                # fill fools mate moves to players move queue
                p0 = game.players[0]
                p0.move_queue.put_nowait(Move(newMove(F2, F3)))
                p0.move_queue.put_nowait(Move(newMove(G2, G4)))

                p1 = gamemodel.players[1]
                p1.move_queue.put_nowait(Move(newMove(E7, E5)))
                p1.move_queue.put_nowait(Move(newMove(D8, H4)))

            gamemodel.connect("players_changed", on_players_changed)

            asyncio.async(self.games_persp.generalStart(gamemodel, player0tup, player1tup))

            # waiting for game end ...
            yield from event.wait()

            fen = "rnb1kbnr/pppp1ppp/8/4p3/6Pq/5P2/PPPPP2P/RNBQKBNR w KQkq - 1 3"
            self.assertEqual(gamemodel.boards[-1].board.asFen(), fen)

            # Now save our game to pychess.pgn
            self.games_persp.saveGamePGN(gamemodel)

        loop.run_until_complete(coro())

    def test2(self):
        """ Import world_matches.pgn into pychess.pgn """

        def on_chessfile_opened(persp, cf):
            self.assertEqual(self.database_persp.chessfile.count, 1)

            self.database_persp.importing(["gamefiles/world_matches.pgn", ])
            # We saved 1 game in test1 and world_matches.pgn has 580 games
            self.assertEqual(self.database_persp.chessfile.count, 581)

        self.database_persp.connect("chessfile_opened", on_chessfile_opened)
        self.database_persp.open_chessfile(test_pgn)

    def test3(self):
        """ Filter pychess.pgn by Kasparov as white """

        def on_chessfile_opened(persp, cf):
            self.assertEqual(self.database_persp.chessfile.count, 581)

            fp = self.database_persp.filter_panel
            name_filter = {"white": "Kasparov"}
            fp.ini_widgets_from_query(name_filter)
            tag_query, material_query, pattern_query = fp.get_queries_from_widgets()
            self.assertEqual(tag_query, name_filter)

            selection = fp.get_selection()
            model, treeiter = selection.get_selected()
            fp.treestore.append(treeiter, [formatted(tag_query), tag_query, TAG_FILTER, RULE])
            fp.filtered = True
            fp.update_filters()
            # world_matches.pgn has 49 games where Kasparov was white
            self.assertEqual(len(self.database_persp.gamelist.records), 49)

        self.database_persp.connect("chessfile_opened", on_chessfile_opened)
        self.database_persp.open_chessfile(test_pgn)
Exemple #17
0
class DialogTests(unittest.TestCase):
    def setUp(self):
        if sys.platform == "win32":
            from asyncio.windows_events import ProactorEventLoop
            loop = ProactorEventLoop()
            asyncio.set_event_loop(loop)
        else:
            loop = asyncio.SelectorEventLoop()
            asyncio.set_event_loop(loop)

        self.loop = asyncio.get_event_loop()
        self.loop.set_debug(enabled=True)

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

    def tearDown(self):
        self.games_persp.gamewidgets.clear()

    def test0(self):
        """ Open engines dialogs """

        # engines dialog
        enginesDialog.run(gamewidget.getWidgets())
        engines = [item[1] for item in enginesDialog.engine_dialog.allstore]
        self.assertTrue("PyChess.py" in engines)

    def test1(self):
        """ Open new game dialog """

        dialog = newGameDialog.NewGameMode()

        async def coro(dialog):
            def on_gmwidg_created(persp, gmwidg, event):
                event.set()

            event = asyncio.Event()
            self.games_persp.connect("gmwidg_created", on_gmwidg_created,
                                     event)

            dialog.run()
            dialog.widgets["newgamedialog"].response(Gtk.ResponseType.OK)

            await event.wait()

        self.loop.run_until_complete(coro(dialog))

    def test2(self):
        """ Open setup position dialog """

        dialog = newGameDialog.SetupPositionExtension()

        async def coro(dialog):
            def on_gmwidg_created(persp, gmwidg, event):
                event.set()

            event = asyncio.Event()
            self.games_persp.connect("gmwidg_created", on_gmwidg_created,
                                     event)

            dialog.run(FEN_START, NORMALCHESS)
            dialog.widgets["newgamedialog"].response(INITIAL)
            dialog.widgets["newgamedialog"].response(COPY)
            dialog.widgets["newgamedialog"].response(CLEAR)
            dialog.widgets["newgamedialog"].response(PASTE)
            dialog.widgets["newgamedialog"].response(Gtk.ResponseType.OK)

            await event.wait()

        self.loop.run_until_complete(coro(dialog))

    @unittest.skipIf(
        sys.platform == "win32",
        "Windows produces TypeError: could not get a reference to type class\n"
        + "on line: cls.sourcebuffer = GtkSource.Buffer()")
    def test3(self):
        """ Start a new game from enter notation dialog """

        dialog = newGameDialog.EnterNotationExtension()

        async def coro(dialog):
            def on_gmwidg_created(persp, gmwidg, event):
                event.set()

            event = asyncio.Event()
            self.games_persp.connect("gmwidg_created", on_gmwidg_created,
                                     event)

            dialog.run()
            dialog.sourcebuffer.set_text("1. f3 e5 2. g4 Qh4")
            dialog.widgets["newgamedialog"].response(Gtk.ResponseType.OK)

            await event.wait()

        self.loop.run_until_complete(coro(dialog))

        # Show the firs move of the game
        async def coro1():

            def on_shown_changed(view, shown, event):
                if shown == 1:
                    event.set()

            gmwidg = self.games_persp.gamewidgets.pop()
            view = gmwidg.board.view
            board = gmwidg.gamemodel.boards[1]

            event = asyncio.Event()
            view.connect("shownChanged", on_shown_changed, event)

            view.setShownBoard(board)

            await event.wait()

        self.loop.run_until_complete(coro1())

    def test4(self):
        """ Open preferences dialog """

        widgets = gamewidget.getWidgets()
        preferencesDialog.run(widgets)

        notebook = widgets["preferences_notebook"]
        self.assertIsNotNone(preferencesDialog.general_tab)

        notebook.next_page()
        self.assertIsNotNone(preferencesDialog.hint_tab)

        notebook.next_page()
        self.assertIsNotNone(preferencesDialog.theme_tab)

        notebook.next_page()
        self.assertIsNotNone(preferencesDialog.sound_tab)

        notebook.next_page()
        self.assertIsNotNone(preferencesDialog.save_tab)

    def test5(self):
        """ Open engine discoverer dialog """
        dd = DiscovererDialog(discoverer)

        async def coro():
            def on_all_engines_discovered(discoverer, event):
                event.set()

            event = asyncio.Event()
            discoverer.connect("all_engines_discovered",
                               on_all_engines_discovered, event)

            create_task(dd.start())

            await event.wait()

        self.loop.run_until_complete(coro())
Exemple #18
0
class ObserveGameTests(EmittingTestCase):
    def setUp(self):
        EmittingTestCase.setUp(self)
        self.loop.set_debug(enabled=True)

        self.manager = self.connection.bm

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.fics_persp = FICS()
        perspective_manager.add_perspective(self.fics_persp)

        self.fics_persp.connection = self.connection
        self.connection.bm.connect("obsGameCreated", self.fics_persp.onObserveGameCreated)
        self.connection.bm.connect("exGameCreated", self.fics_persp.onObserveGameCreated)

    def test1(self):
        """ Test following lecturebot starting new lecture after finishing previous one """

        lines = [
            'LectureBot(TD)(----)[1] kibitzes: That concludes this lecture. If this lecture inspired you to write your own lecture, "finger LectureBot" and read note 8. toddmf would really like to hear from you about LectureBot. Please send him comments! Hope to see you all again soon!',
            'fics% ',
            'LectureBot stopped examining game 1.',
            '',
            'Game 1 (which you were observing) has no examiners.',
            'Removing game 1 from observation list.',
            'fics% ',
            'LectureBot, whom you are following, has started examining a game.',
            'You are now observing game 1.',
            'Game 1: LectureBot (0) LectureBot (0) unrated untimed 0 0',
            '',
            '<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 1 LectureBot LectureBot -2 0 0 39 39 0 0 1 none (0:00.000) none 0 0 0',
        ]

        signal = 'obsGameCreated'

        game = FICSGame(
            FICSPlayer("LectureBot"),
            FICSPlayer("LectureBot"),
            gameno=1)
        game = self.connection.games.get(game)
        expectedResults = (game, )
        self.runAndAssertEquals(signal, lines, expectedResults)

        print(self.games_persp.cur_gmwidg().gamemodel)

        lines = [
            '<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 1 Henley LectureBot -2 0 0 39 39 0 0 1 none (0:00.000) none 0 0 0',
            '<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 1 Henley Browne -2 0 0 39 39 0 0 1 none (0:00.000) none 0 0 0',
            '<12> rnbqkbnr pppppppp -------- -------- -------- -----N-- PPPPPPPP RNBQKB-R B -1 1 1 1 1 1 1 Henley Browne -2 0 0 39 39 0 0 1 N/g1-f3 (0:00.000) Nf3 0 0 0',
            'fics% ',
            'Game 1: LectureBot moves: Nf3',
        ]

        async def coro():
            await self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel)

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 1)

        lines = [
            '<12> rnbqkbnr pp-ppppp -------- --p----- -------- -----N-- PPPPPPPP RNBQKB-R W 2 1 1 1 1 0 1 Henley Browne -2 0 0 39 39 0 0 2 P/c7-c5 (0:00.000) c5 0 0 0',
            'fics% ',
            'Game 1: LectureBot moves: c5',
            '<12> rnbqkbnr pp-ppppp -------- --p----- -------- -----NP- PPPPPP-P RNBQKB-R B -1 1 1 1 1 0 1 Henley Browne -2 0 0 39 39 0 0 2 P/g2-g3 (0:00.000) g3 0 0 0',
            'fics% '
            'Game 1: LectureBot moves: g3',
            '<12> rnbqkbnr p--ppppp -p------ --p----- -------- -----NP- PPPPPP-P RNBQKB-R W -1 1 1 1 1 0 1 Henley Browne -2 0 0 39 39 0 0 3 P/b7-b6 (0:00.000) b6 0 0 0',
            'fics% '
            'Game 1: LectureBot moves: b6',
        ]

        async def coro():
            await self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel)

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 4)

    def test2(self):
        """ Test manual examine lecturebot lec2 """

        lines = [
            # examine
            BLOCK_START + '62' + BLOCK_SEPARATOR + '36' + BLOCK_SEPARATOR,
            'Starting a game in examine (scratch) mode.',
            '',
            '<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 77 gbtami gbtami 2 0 0 39 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
        ]

        signal = 'exGameCreated'

        game = FICSGame(
            FICSPlayer("gbtami"),
            FICSPlayer("gbtami"),
            gameno=77)
        game = self.connection.games.get(game)
        expectedResults = (game, )
        self.runAndAssertEquals(signal, lines, expectedResults)

        print(self.games_persp.cur_gmwidg().gamemodel)

        lines = [
            # bsetup
            BLOCK_START + '63' + BLOCK_SEPARATOR + '21' + BLOCK_SEPARATOR,
            "Entering setup mode.",
            'fics% ',
            BLOCK_END,
            # bsetup fen r1bq2k1/2p2p1p/p1pp2pB/2n4r/8/2N2Q2/PPP2PPP/4RRK1
            BLOCK_START + '64' + BLOCK_SEPARATOR + '21' + BLOCK_SEPARATOR,
            '<12> r-bq--k- --p--p-p p-pp--pB --n----r -------- --N--Q-- PPP--PPP ----RRK- W -1 1 1 1 1 0 77 gbtami gbtami 2 0 0 39 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # bsetup wcastle none
            BLOCK_START + '65' + BLOCK_SEPARATOR + '21' + BLOCK_SEPARATOR,
            '<12> r-bq--k- --p--p-p p-pp--pB --n----r -------- --N--Q-- PPP--PPP ----RRK- W -1 0 0 1 1 0 77 gbtami gbtami 2 0 0 39 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # bsetup bcastle none
            BLOCK_START + '66' + BLOCK_SEPARATOR + '21' + BLOCK_SEPARATOR,
            '<12> r-bq--k- --p--p-p p-pp--pB --n----r -------- --N--Q-- PPP--PPP ----RRK- W -1 0 0 0 0 0 77 gbtami gbtami 2 0 0 39 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # tomove white
            BLOCK_START + '67' + BLOCK_SEPARATOR + '134' + BLOCK_SEPARATOR,
            '<12> r-bq--k- --p--p-p p-pp--pB --n----r -------- --N--Q-- PPP--PPP ----RRK- W -1 0 0 0 0 0 77 gbtami gbtami 2 0 0 39 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # bsetup done
            BLOCK_START + '68' + BLOCK_SEPARATOR + '21' + BLOCK_SEPARATOR,
            'Game is validated - entering examine mode.',
            '<12> r-bq--k- --p--p-p p-pp--pB --n----r -------- --N--Q-- PPP--PPP ----RRK- W -1 0 0 0 0 0 77 gbtami gbtami 2 0 0 39 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # wname Honfi
            BLOCK_START + '69' + BLOCK_SEPARATOR + '148' + BLOCK_SEPARATOR,
            '<12> r-bq--k- --p--p-p p-pp--pB --n----r -------- --N--Q-- PPP--PPP ----RRK- W -1 0 0 0 0 0 77 Honfi gbtami 2 0 0 39 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # bname Sebestyen
            BLOCK_START + '70' + BLOCK_SEPARATOR + '19' + BLOCK_SEPARATOR,
            '<12> r-bq--k- --p--p-p p-pp--pB --n----r -------- --N--Q-- PPP--PPP ----RRK- W -1 0 0 0 0 0 77 Honfi Sebestyen 2 0 0 39 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # f3f6
            BLOCK_START + '71' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> r-bq--k- --p--p-p p-pp-QpB --n----r -------- --N----- PPP--PPP ----RRK- B -1 0 0 0 0 1 77 Honfi Sebestyen 2 0 0 39 39 0 0 1 Q/f3-f6 (0:00.000) Qf6 0 0 0',
            'Game 77: gbtami moves: Qf6',
            'fics% ',
            BLOCK_END,
            # d8f6
            BLOCK_START + '72' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> r-b---k- --p--p-p p-pp-qpB --n----r -------- --N----- PPP--PPP ----RRK- W -1 0 0 0 0 0 77 Honfi Sebestyen 2 0 0 30 39 0 0 2 Q/d8-f6 (0:00.000) Qxf6 0 0 0',
            'Game 119: gbtami moves: Qxf6',
            'fics% ',
            BLOCK_END,
            # e1e8
            BLOCK_START + '73' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> r-b-R-k- --p--p-p p-pp-qpB --n----r -------- --N----- PPP--PPP -----RK- B -1 0 0 0 0 1 77 Honfi Sebestyen 2 0 0 30 39 0 0 2 R/e1-e8 (0:00.000) Re8# 0 0 0',
            'Game 119: gbtami moves: Re8#',
            'Game 119: Black checkmated 1-0',
            'fics% ',
            BLOCK_END,
        ]

        async def coro():
            await self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[-1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 3)

        lines = [
            # kibitz Example 2:...
            BLOCK_START + '74' + BLOCK_SEPARATOR + '21' + BLOCK_SEPARATOR,
            'gbtami(1719)[77] kibitzes: Example 2: Dementyev vs Karpov, Riga 1971',
            BLOCK_END,
            # bsetup
            BLOCK_START + '75' + BLOCK_SEPARATOR + '21' + BLOCK_SEPARATOR,
            "Entering setup mode.",
            'fics% ',
            BLOCK_END,
            # bsetup fen q3r1k1/4Rp1p/6p1/2Q1B3/P2P4/1r1b3P/5PP1/4R1K1
            BLOCK_START + '76' + BLOCK_SEPARATOR + '21' + BLOCK_SEPARATOR,
            '<12> q---r-k- ----Rp-p ------p- --Q-B--- P--P---- -r-b---P -----PP- ----R-K- B -1 0 0 0 0 0 77 Honfi Sebestyen 2 0 0 30 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # bsetup wcastle none
            BLOCK_START + '77' + BLOCK_SEPARATOR + '21' + BLOCK_SEPARATOR,
            '<12> q---r-k- ----Rp-p ------p- --Q-B--- P--P---- -r-b---P -----PP- ----R-K- B -1 0 0 0 0 0 77 Honfi Sebestyen 2 0 0 30 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # bsetup bcastle none
            BLOCK_START + '78' + BLOCK_SEPARATOR + '21' + BLOCK_SEPARATOR,
            '<12> q---r-k- ----Rp-p ------p- --Q-B--- P--P---- -r-b---P -----PP- ----R-K- B -1 0 0 0 0 0 77 Honfi Sebestyen 2 0 0 30 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # tomove white
            BLOCK_START + '79' + BLOCK_SEPARATOR + '134' + BLOCK_SEPARATOR,
            '<12> q---r-k- ----Rp-p ------p- --Q-B--- P--P---- -r-b---P -----PP- ----R-K- W -1 0 0 0 0 0 77 Honfi Sebestyen 2 0 0 30 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # bsetup done
            BLOCK_START + '80' + BLOCK_SEPARATOR + '21' + BLOCK_SEPARATOR,
            'Game is validated - entering examine mode.',
            '<12> q---r-k- ----Rp-p ------p- --Q-B--- P--P---- -r-b---P -----PP- ----R-K- W -1 0 0 0 0 0 77 Honfi Sebestyen 2 0 0 30 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # wname Dementyev
            BLOCK_START + '81' + BLOCK_SEPARATOR + '148' + BLOCK_SEPARATOR,
            '<12> q---r-k- ----Rp-p ------p- --Q-B--- P--P---- -r-b---P -----PP- ----R-K- W -1 0 0 0 0 0 77 Dementyev Sebestyen 2 0 0 30 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # bname Karpov
            BLOCK_START + '82' + BLOCK_SEPARATOR + '19' + BLOCK_SEPARATOR,
            '<12> q---r-k- ----Rp-p ------p- --Q-B--- P--P---- -r-b---P -----PP- ----R-K- W -1 0 0 0 0 0 77 Dementyev Karpov 2 0 0 30 39 0 0 1 none (0:00.000) none 0 0 0',
            'fics% ',
            BLOCK_END,
            # c5d5
            BLOCK_START + '83' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            '<12> q---r-k- ----Rp-p ------p- ---QB--- P--P---- -r-b---P -----PP- ----R-K- B -1 0 0 0 0 1 77 Dementyev Karpov 2 0 0 30 39 0 0 1 Q/c5-d5 (0:00.000) Qd5 0 0 0',
            'Game 119: gbtami moves: Qd5',
            'fics% ',
            BLOCK_END,
        ]

        async def coro():
            await self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        print(self.games_persp.cur_gmwidg().gamemodel.boards[1])

        self.assertEqual(self.games_persp.cur_gmwidg().gamemodel.ply, 1)
Exemple #19
0
class DatabaseTests(unittest.TestCase):
    def setUp(self):
        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.database_persp = Database()
        perspective_manager.add_perspective(self.database_persp)
        self.database_persp.create_toolbuttons()

    def test1(self):
        """ Play and save Human-Human 1 min game """

        loop = asyncio.get_event_loop()
        loop.set_debug(enabled=True)

        def coro():
            gamemodel = GameModel(TimeModel(1, 0))

            player0tup = (LOCAL, Human, (WHITE, "w"), "w")
            player1tup = (LOCAL, Human, (BLACK, "b"), "b")

            def on_game_end(game, state, event):
                event.set()

            event = asyncio.Event()
            gamemodel.connect("game_ended", on_game_end, event)

            def on_players_changed(game):
                # fill fools mate moves to players move queue
                p0 = game.players[0]
                p0.move_queue.put_nowait(Move(newMove(F2, F3)))
                p0.move_queue.put_nowait(Move(newMove(G2, G4)))

                p1 = gamemodel.players[1]
                p1.move_queue.put_nowait(Move(newMove(E7, E5)))
                p1.move_queue.put_nowait(Move(newMove(D8, H4)))

            gamemodel.connect("players_changed", on_players_changed)

            asyncio. async (self.games_persp.generalStart(
                gamemodel, player0tup, player1tup))

            # waiting for game end ...
            yield from event.wait()

            fen = "rnb1kbnr/pppp1ppp/8/4p3/6Pq/5P2/PPPPP2P/RNBQKBNR w KQkq - 1 3"
            self.assertEqual(gamemodel.boards[-1].board.asFen(), fen)

            # Now save our game to pychess.pgn
            self.games_persp.saveGamePGN(gamemodel)

        loop.run_until_complete(coro())

    def test2(self):
        """ Import world_matches.pgn into pychess.pgn """
        def on_chessfile_opened(persp, cf):
            self.assertEqual(self.database_persp.chessfile.count, 1)

            self.database_persp.importing([
                "gamefiles/world_matches.pgn",
            ])
            # We saved 1 game in test1 and world_matches.pgn has 580 games
            self.assertEqual(self.database_persp.chessfile.count, 581)

        self.database_persp.connect("chessfile_opened", on_chessfile_opened)
        self.database_persp.open_chessfile(test_pgn)

    def test3(self):
        """ Filter pychess.pgn by Kasparov as white """
        def on_chessfile_opened(persp, cf):
            self.assertEqual(self.database_persp.chessfile.count, 581)

            fp = self.database_persp.filter_panel
            name_filter = {"white": "Kasparov"}
            fp.ini_widgets_from_query(name_filter)
            tag_query, material_query, pattern_query = fp.get_queries_from_widgets(
            )
            self.assertEqual(tag_query, name_filter)

            selection = fp.get_selection()
            model, treeiter = selection.get_selected()
            fp.treestore.append(
                treeiter, [formatted(tag_query), tag_query, TAG_FILTER, RULE])
            fp.filtered = True
            fp.update_filters()
            # world_matches.pgn has 49 games where Kasparov was white
            self.assertEqual(len(self.database_persp.gamelist.records), 49)

        self.database_persp.connect("chessfile_opened", on_chessfile_opened)
        self.database_persp.open_chessfile(test_pgn)
Exemple #20
0
class PlayGameTests(EmittingTestCase):
    def setUp(self):
        EmittingTestCase.setUp(self)
        self.manager = self.connection.bm

    def test1(self):
        """ From gbtami (player accepting a challenge) point of view """
        lines = [
            "Challenge: ggbtami (----) gbtami (1708) unrated blitz 5 0.",
            'You can "accept" or "decline", or propose different parameters.',
            "fics% ",
            "<pf> 7 w=ggbtami t=match p=ggbtami (----) gbtami (1708) unrated blitz 5 0",
            "fics% ",
            BLOCK_START + '52' + BLOCK_SEPARATOR + '11' + BLOCK_SEPARATOR,
            "You accept the match offer from ggbtami."
            "",
            "",
            "<pr> 7",
            "fics% ",
            "Creating: gbtami (1708) ggbtami (++++) unrated blitz 5 0",
            "{Game 107 (gbtami vs. ggbtami) Creating unrated blitz match.}"
            "",
            "",
            "<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 107 gbtami ggbtami 1 5 0 39 39 300000 300000 1 none (0:00.000) none 0 0 0",
            ""
            ""
            "Game 107: A disconnection will be considered a forfeit.",
            BLOCK_END,
            "fics% '"]

        me = self.connection.players.get('gbtami')
        me.ratings[TYPE_BLITZ] = 1708
        opponent = self.connection.players.get('ggbtami')
        opponent.ratings[TYPE_BLITZ] = 0
        game = FICSGame(me,
                        opponent,
                        gameno=107,
                        rated=False,
                        game_type=GAME_TYPES['blitz'],
                        private=False,
                        minutes=5,
                        inc=0,
                        board=FICSBoard(300000,
                                        300000,
                                        fen=FEN_START))
        me.game = game
        opponent.game = game
        self.runAndAssertEquals("playGameCreated", lines, (game, ))

        lines = [
            BLOCK_START + '58' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            "<12> rnbqkbnr pppppppp -------- -------- -------- -----P-- PPPPP-PP RNBQKBNR B -1 1 1 1 1 0 107 gbtami ggbtami -1 5 0 39 39 300000 300000 1 P/f2-f3 (0:00.000) f3 0 0 0",
            BLOCK_END,
            "fics% ",
            "<12> rnbqkbnr pppp-ppp -------- ----p--- -------- -----P-- PPPPP-PP RNBQKBNR W 4 1 1 1 1 0 107 gbtami ggbtami 1 5 0 39 39 300000 300000 2 P/e7-e5 (0:00.000) e5 0 1 0",
            "fics% ",
            BLOCK_START + '61' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            "<12> rnbqkbnr pppp-ppp -------- ----p--- ------P- -----P-- PPPPP--P RNBQKBNR B 6 1 1 1 1 0 107 gbtami ggbtami -1 5 0 39 39 297338 300000 2 P/g2-g4 (0:02.662) g4 0 1 296",
            BLOCK_END,
            "fics% ",
            "<12> rnb-kbnr pppp-ppp -------- ----p--- ------Pq -----P-- PPPPP--P RNBQKBNR W -1 1 1 1 1 1 107 gbtami ggbtami 1 5 0 39 39 297338 295763 3 Q/d8-h4 (0:04.237) Qh4# 0 1 304",
            "fics% ",
            "{Game 107 (gbtami vs. ggbtami) gbtami checkmated} 0-1",
            "No ratings adjustment done.",
            "fics% "]

        game = self.connection.games[game]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 4)
        self.assertEqual(game.reason, WON_MATE)

    def test2(self):
        """ From ggbtami (player sending a challenge) point of view """
        lines = [
            BLOCK_START + '54' + BLOCK_SEPARATOR + '73' + BLOCK_SEPARATOR,
            "Issuing: ggbtami (----) gbtami (1708) unrated blitz 5 0.",
            "<pt> 7 w=gbtami t=match p=ggbtami (----) gbtami (1708) unrated blitz 5 0",
            "fics% ",
            BLOCK_END,
            "gbtami accepts the match offer.",
            "<pr> 7",
            "fics% ",
            "Creating: gbtami (1708) ggbtami (++++) unrated blitz 5 0",
            "{Game 107 (gbtami vs. ggbtami) Creating unrated blitz match.}"
            "",
            "",
            "<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 107 gbtami ggbtami 1 5 0 39 39 300000 300000 1 none (0:00.000) none 0 0 0",
            ""
            ""
            "Game 107: A disconnection will be considered a forfeit.",
            BLOCK_END,
            "fics% '"]

        me = self.connection.players.get('gbtami')
        me.ratings[TYPE_BLITZ] = 1708
        opponent = self.connection.players.get('ggbtami')
        opponent.ratings[TYPE_BLITZ] = 0
        game = FICSGame(me,
                        opponent,
                        gameno=107,
                        rated=False,
                        game_type=GAME_TYPES['blitz'],
                        private=False,
                        minutes=5,
                        inc=0,
                        board=FICSBoard(300000,
                                        300000,
                                        fen=FEN_START))
        me.game = game
        opponent.game = game
        self.runAndAssertEquals("playGameCreated", lines, (game, ))

        lines = [
            "<12> rnbqkbnr pppppppp -------- -------- -------- -----P-- PPPPP-PP RNBQKBNR B -1 1 1 1 1 0 107 gbtami ggbtami -1 5 0 39 39 300000 300000 1 P/f2-f3 (0:00.000) f3 0 0 0",
            "fics% ",
            BLOCK_START + '61' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            "<12> rnbqkbnr pppp-ppp -------- ----p--- -------- -----P-- PPPPP-PP RNBQKBNR W 4 1 1 1 1 0 107 gbtami ggbtami 1 5 0 39 39 300000 300000 2 P/e7-e5 (0:00.000) e5 0 1 0",
            BLOCK_END,
            "fics% ",
            "<12> rnbqkbnr pppp-ppp -------- ----p--- ------P- -----P-- PPPPP--P RNBQKBNR B 6 1 1 1 1 0 107 gbtami ggbtami -1 5 0 39 39 297338 300000 2 P/g2-g4 (0:02.662) g4 0 1 296",
            "fics% ",
            BLOCK_START + '64' + BLOCK_SEPARATOR + '1' + BLOCK_SEPARATOR,
            "<12> rnb-kbnr pppp-ppp -------- ----p--- ------Pq -----P-- PPPPP--P RNBQKBNR W -1 1 1 1 1 1 107 gbtami ggbtami 1 5 0 39 39 297338 295763 3 Q/d8-h4 (0:04.237) Qh4# 0 1 304",
            "{Game 107 (gbtami vs. ggbtami) gbtami checkmated} 0-1",
            "No ratings adjustment done.",
            BLOCK_END,
            "fics% "]

        game = self.connection.games[game]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 4)
        self.assertEqual(game.reason, WON_MATE)

    def test3(self):
        """ Accepting a seek """

        loop = asyncio.get_event_loop()
        loop.set_debug(enabled=True)

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

        self.fics_persp = FICS()
        perspective_manager.add_perspective(self.fics_persp)
        self.fics_persp.create_toolbuttons()

        self.lounge = perspective_manager.get_perspective("fics")
        self.lounge.open_lounge(self.connection, self.connection, "freechess.org")

        lines = [
            "<s> 11 w=WLTL ti=00 rt=2030  t=1 i=0 r=r tp=lightning c=? rr=0-9999 a=t f=f",
            "fics% ",
            BLOCK_START + "52" + BLOCK_SEPARATOR + "158" + BLOCK_SEPARATOR,
            "<sr> 11 16",
            "fics% ",
            "Creating: WLTL (2030) gbtami (1771) rated lightning 1 0",
            "{Game 85 (WLTL vs. gbtami) Creating rated lightning match.}",
            "",
            "<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 85 WLTL gbtami -1 1 0 39 39 60000 60000 1 none (0:00.000) none 1 0 0\n\nGame 85: A disconnection will be considered a forfeit.",
            BLOCK_END,
            "fics% "]

        me = self.connection.players.get('gbtami')
        me.ratings[TYPE_LIGHTNING] = 1771
        opponent = self.connection.players.get('WLTL')
        opponent.ratings[TYPE_LIGHTNING] = 2030
        game = FICSGame(opponent,
                        me,
                        gameno=85,
                        rated=True,
                        game_type=GAME_TYPES['lightning'],
                        private=False,
                        minutes=1,
                        inc=0,
                        board=FICSBoard(60000,
                                        60000,
                                        fen=FEN_START))
        me.game = game
        opponent.game = game
        self.runAndAssertEquals("playGameCreated", lines, (game, ))

        gamemodel = self.games_persp.cur_gmwidg().gamemodel

        def on_game_started(game):
            p1 = gamemodel.players[1]
            p1.move_queue.put_nowait(Move(newMove(G8, F6)))

        gamemodel.connect("game_started", on_game_started)

        lines = [
            "<12> rnbqkbnr pppppppp -------- -------- -------- -P------ P-PPPPPP RNBQKBNR B -1 1 1 1 1 0 85 WLTL gbtami 1 1 0 39 39 60000 60000 1 P/b2-b3 (0:00.000) b3 1 0 0",
            "fics% "]

        game = self.connection.games[game]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)

        lines = [
            BLOCK_START + "59" + BLOCK_SEPARATOR + "1" + BLOCK_SEPARATOR,
            "<12> rnbqkb-r pppppppp -----n-- -------- -------- -P------ P-PPPPPP RNBQKBNR W -1 1 1 1 1 1 85 WLTL gbtami -1 1 0 39 39 60000 60000 2 N/g8-f6 (0:00.000) Nf6 1 1 0",
            BLOCK_END,
            "fics% ",
            "<12> rnbqkb-r pppppppp -----n-- -------- -------- -P----P- P-PPPP-P RNBQKBNR B -1 1 1 1 1 0 85 WLTL gbtami 1 1 0 39 39 59900 60000 2 P/g2-g3 (0:00.100) g3 1 1 285",
            "fics% "]

        def coro():
            yield from self.connection.process_lines(lines)
        self.loop.run_until_complete(coro())

        self.assertEqual(game.move_queue.qsize(), 0)
        self.assertEqual(gamemodel.ply, 3)
        print(gamemodel.boards[-1])
Exemple #21
0
class DialogTests(unittest.TestCase):
    def setUp(self):
        if sys.platform == "win32":
            from asyncio.windows_events import ProactorEventLoop
            loop = ProactorEventLoop()
            asyncio.set_event_loop(loop)
        else:
            loop = asyncio.SelectorEventLoop()
            asyncio.set_event_loop(loop)

        self.loop = asyncio.get_event_loop()
        self.loop.set_debug(enabled=True)

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp)

    def tearDown(self):
        self.games_persp.gamewidgets.clear()

    def test0(self):
        """ Open engines dialogs """

        # engines dialog
        enginesDialog.run(gamewidget.getWidgets())
        engines = [item[1] for item in enginesDialog.engine_dialog.allstore]
        self.assertTrue("PyChess.py" in engines)

    def test1(self):
        """ Open new game dialog """

        dialog = newGameDialog.NewGameMode()

        @asyncio.coroutine
        def coro(dialog):
            def on_gmwidg_created(persp, gmwidg, event):
                event.set()

            event = asyncio.Event()
            self.games_persp.connect("gmwidg_created", on_gmwidg_created, event)

            dialog.run()
            dialog.widgets["newgamedialog"].response(Gtk.ResponseType.OK)

            yield from event.wait()

        self.loop.run_until_complete(coro(dialog))

    def test2(self):
        """ Open setup position dialog """

        dialog = newGameDialog.SetupPositionExtension()

        @asyncio.coroutine
        def coro(dialog):
            def on_gmwidg_created(persp, gmwidg, event):
                event.set()

            event = asyncio.Event()
            self.games_persp.connect("gmwidg_created", on_gmwidg_created, event)

            dialog.run(FEN_START, NORMALCHESS)
            dialog.widgets["newgamedialog"].response(INITIAL)
            dialog.widgets["newgamedialog"].response(COPY)
            dialog.widgets["newgamedialog"].response(CLEAR)
            dialog.widgets["newgamedialog"].response(PASTE)
            dialog.widgets["newgamedialog"].response(Gtk.ResponseType.OK)

            yield from event.wait()

        self.loop.run_until_complete(coro(dialog))

    @unittest.skipIf(sys.platform == "win32",
                     "Windows produces TypeError: could not get a reference to type class\n" + 
                     "on line: cls.sourcebuffer = GtkSource.Buffer()")
    def test3(self):
        """ Start a new game from enter notation dialog """

        dialog = newGameDialog.EnterNotationExtension()

        @asyncio.coroutine
        def coro(dialog):
            def on_gmwidg_created(persp, gmwidg, event):
                event.set()

            event = asyncio.Event()
            self.games_persp.connect("gmwidg_created", on_gmwidg_created, event)

            dialog.run()
            dialog.sourcebuffer.set_text("1. f3 e5 2. g4 Qh4")
            dialog.widgets["newgamedialog"].response(Gtk.ResponseType.OK)

            yield from event.wait()

        self.loop.run_until_complete(coro(dialog))

        # Show the firs move of the game
        @asyncio.coroutine
        def coro1():
            def on_shown_changed(view, shown, event):
                if shown == 1:
                    event.set()

            gmwidg = self.games_persp.gamewidgets.pop()
            view = gmwidg.board.view
            board = gmwidg.gamemodel.boards[1]

            event = asyncio.Event()
            view.connect("shownChanged", on_shown_changed, event)

            view.setShownBoard(board)

            yield from event.wait()

        self.loop.run_until_complete(coro1())

    def test4(self):
        """ Open preferences dialog """

        widgets = gamewidget.getWidgets()
        preferencesDialog.run(widgets)

        notebook = widgets["preferences_notebook"]
        self.assertIsNotNone(preferencesDialog.general_tab)

        notebook.next_page()
        self.assertIsNotNone(preferencesDialog.hint_tab)

        notebook.next_page()
        self.assertIsNotNone(preferencesDialog.theme_tab)

        notebook.next_page()
        self.assertIsNotNone(preferencesDialog.sound_tab)

        notebook.next_page()
        self.assertIsNotNone(preferencesDialog.save_tab)

    def test5(self):
        """ Open engine discoverer dialog """
        dd = DiscovererDialog(discoverer)

        @asyncio.coroutine
        def coro():
            def on_all_engines_discovered(discoverer, event):
                event.set()

            event = asyncio.Event()
            discoverer.connect("all_engines_discovered", on_all_engines_discovered, event)

            create_task(dd.start())

            yield from event.wait()

        self.loop.run_until_complete(coro())