Beispiel #1
0
    def hfen(self):
        state = HexachromixState(variant=self.variant)

        for move in self.moves:
            state = state.make_move((move.q, move.r))

        return state.hfen
Beispiel #2
0
def view_game(request, game_uid):
    try:
        game = Game.objects.get(uid=game_uid)
    except Game.DoesNotExist:
        return HttpResponse("game %s not found" % game_uid)

    if game.is_active:
        # Make sure a session exists so the channel can generate a player identifier.
        if not request.session.session_key:
            request.session.create()

        return render(request, 'hexachromix/play.html', {'game': game})
    else:
        state = HexachromixState(variant=game.variant)

        moves = []
        for move in game.moves:
            state = state.make_move((move.q, move.r))
            moves.append({
                'color': move.color,
                'q': move.q,
                'r': move.r,
                'hfen': state.hfen,
            })

        return render(request, 'hexachromix/view_game.html', {
            'game': game,
            'moves': moves
        })
Beispiel #3
0
    def hfen(self):
        state = HexachromixState(variant=self.game.variant)

        for move in self.game.moves:
            state = state.make_move((move.q, move.r))
            if self is move:
                break

        return state.hfen
Beispiel #4
0
 def test_state_from_hfen(self):
     hfens = [
         '3/4/5/4/3 M MR',
         'RRR/RRRR/RRRRR/RRRR/RRR M MR',
         'R1R/RRRR/RRRRR/RRRR/RRR M MR',
         '1R1/2R1/2R2/2R1/1R1 M MR',
     ]
     for hfen in hfens:
         state = HexachromixState.state_from_hfen(hfen)
         self.assertEqual(state.hfen, hfen)
         self.assertEqual(state.get_current_color(), Move.Color.M)
         self.assertEqual(state.variant, Game.Variant.MR)
Beispiel #5
0
    def test_get_legal_moves(self):
        state = HexachromixState()
        self.assertEqual(state.get_current_color(), Move.Color.R)
        self.assertEqual(len(state.get_legal_moves()), 19)

        self.assertEqual(
            len(
                HexachromixState.state_from_hfen(
                    '3/4/5/4/3 R MRY').get_legal_moves()), 19)
        self.assertEqual(
            len(
                HexachromixState.state_from_hfen(
                    'R2/4/5/4/3 R MRY').get_legal_moves()), 18)
        self.assertEqual(
            len(
                HexachromixState.state_from_hfen(
                    'RRR/RRRR/RRRRR/RRRR/RRR R MRY').get_legal_moves()), 0)
Beispiel #6
0
    def test_did_win(self):
        self.assertEqual(
            HexachromixState.state_from_hfen('R2/R3/R4/R3/R2 Y MRY').did_win(),
            True)
        self.assertEqual(
            HexachromixState.state_from_hfen('C2/C3/C4/C3/C2 B MRY').did_win(),
            True)
        self.assertEqual(
            HexachromixState.state_from_hfen('C2/C3/5/C3/C2 B MRY').did_win(),
            False)

        self.assertEqual(
            HexachromixState.state_from_hfen('3/4/BBBBB/4/3 M MRY').did_win(),
            True)
        self.assertEqual(
            HexachromixState.state_from_hfen('3/4/MMMMM/4/3 R MRY').did_win(),
            True)
        self.assertEqual(
            HexachromixState.state_from_hfen('3/4/YYYYY/4/3 G MRY').did_win(),
            True)
        self.assertEqual(
            HexachromixState.state_from_hfen('3/4/GGGGG/4/3 C MRY').did_win(),
            True)
Beispiel #7
0
 def state_from_hfen(hfen):
     return HexachromixState.state_from_hfen(hfen)
Beispiel #8
0
 def test_is_terminal(self):
     self.assertEqual(
         HexachromixState.state_from_hfen('3/4/5/4/3 R MRY').is_terminal(),
         False)