コード例 #1
0
 def start_new_game(self):
     users = [
         User.get_or_create(display_name=self.black_name,
                            defaults={'token': '1'})[0],
         User.get_or_create(display_name=self.white_name,
                            defaults={'token': '2'})[0]
     ]
     timer = Timer()
     players = {Color.black: users[0], Color.white: users[1]}
     self.game = Game.new_game(size=9,
                               rule_set=get_japanese_rule_set(),
                               players=players,
                               timer=timer)
     self.game.save()
     self.api.start_game(self.game)
     return self.game
コード例 #2
0
    def _from_sgf(sgf):
        assert isinstance(sgf, SGF)
        uuid = sgf.header.get('UD', None)
        size = sgf.header['SZ']
        rules = get_rule_set_by_name(sgf.header['RU'])
        players = {
            Color.black:
            User.get_or_create(display_name=sgf.header['BP'],
                               defaults={'token': '1'})[0],
            Color.white:
            User.get_or_create(display_name=sgf.header['WP'],
                               defaults={'token': '2'})[0]
        }
        game = Game.new_game(int(size), rules, players, Timer(), uuid=uuid)

        for move in sgf.moves:
            game.make_move(Move.from_sgf(move[game.state.next_color.sgf_str]))
        return game