Esempio n. 1
0
    def test_sgf(self):
        game = GameFactory()

        res = self.fetch('/api/games/%s/sgf' % game.id)
        self.assertEqual(res.code, 200)

        assert res.body.decode() == game_to_sgf(game)
Esempio n. 2
0
def test_game_to_sgf_basic():
    game = Game(board=Board(19),
                black_display='black',
                white_display='white',
                created_at=datetime(2016, 5, 7),
                result='B+1.5',
                komi=7.5)

    game.board.play(coord2d(4, 4, 19))
    game.board.play(coord2d(16, 17, 19))

    sgf = game_to_sgf(game)
    expected = '(;SO[weiqi.gs]FF[4]DT[2016-05-07]PW[white]PB[black]KM[7.5]SZ[19]RE[B+1.5];B[dd];W[pq])'

    assert sgf.replace('\n', '') == expected
Esempio n. 3
0
    def get(self, game_id):
        game = self.db.query(Game).options(undefer('board')).get(game_id)

        if not game:
            raise HTTPError(404)

        filename = '%s-%s-%s.sgf' % (game.created_at.date().isoformat(),
                                     game.white_display, game.black_display)

        self.set_header('Content-Type', 'application/x-go-sgf; charset=utf-8')
        self.set_header('Content-Disposition',
                        'attachment; filename="%s"' % filename)

        self.enable_cors()

        self.write(game_to_sgf(game))