Exemplo n.º 1
0
        def grid_pos(grid):
            """计算出格子中央在字符阵列中的位置

            (0,0) -> (1,1)
            (1,0) -> (3,1)
            (1,1) -> (3,3)

            (x,y) -> (2x+1, 2y+1)
            """
            return 2 * G.x(grid) + 1, 2 * G.y(grid) + 1
Exemplo n.º 2
0
def test_copycat(ntests=1000):
    p1 = CP("Cat1")
    p2 = CP("Cat2")
    _g = G(p1, p2, steps=20)
    for _ in range(ntests):
        with _g as g:
            g.run()
        assert (g.winner() is None)
    _g = G(p1, p2, steps=21)
    for _ in range(ntests):
        with _g as g:
            next(g)
            w = g.p1 if (g.s1 > g.s2) else g.p2 if (g.s2 > g.s1) else None
            g.run()
        assert (g.winner() is w)
    return 0
Exemplo n.º 3
0
 def __next__(self):
     self.game_counter += 1
     if len(self.games) == 0:
         raise StopIteration
     (x, y) = self.games.pop()
     rps.say("Game {:03d}: {:} vs {:}".format(self.game_counter, x, y))
     _g = G(x, y, memory=self.game_memory, steps=self.game_steps)
     with _g as g:
         g.run()
         self.add_score(x,g.s1)\
                 .add_score(y,g.s2)
     self.add_victory(g.winner())
Exemplo n.º 4
0
def run_match(p1, p2, ntests=1000, steps=20):
    score = {p1: 0, p2: 0}
    _g = G(p1, p2, steps=20)
    for _ in range(ntests):
        with _g as g:
            g.run()
        w = g.winner()
        if w is not None:
            score[w] += 1
    s1 = score[p1]
    s2 = score[p2]
    r = abs(s1 - s2) / (s1 + s2)
    return r, s1, s2
Exemplo n.º 5
0
| |0|0| |
+-+-+-+-+
"""
"""
+--+-+-+-+
|张|   | |
+ + + + +
| |   | |
+-+-+-+-+
| |   | |
+ +-+-+ +
| | | | |
+-+-+-+-+
| |0|0| |
+-+-+-+-+
"""

if __name__ == '__main__':
    g = Game()
    print_layout(g, g.initial, chinese=False)

    print()
    print()

    print_layout(g, L(B(G(0, 0), G(0, 1), G(1, 0), G(1, 1))), chinese=False)

    print()
    print()

    print_layout(g, L(B(G(1, 3), G(2, 3), G(1, 4), G(2, 4))), chinese=False)
Exemplo n.º 6
0
class Game98(Game):
    title = '逗逼n国'

    width = 5
    height = 5

    initial = L(B(G(1, 3), G(2, 3), G(1, 4), G(2, 4), cap='曹'),
                B(G(0, 3), cap='董'), B(G(0, 2), G(0, 1), G(1, 2), cap='刘'),
                B(G(3, 2), G(4, 2), cap='吕'), B(G(3, 3), cap='陶'),
                B(G(4, 3), G(3, 4), G(4, 4), cap='袁'),
                B(G(3, 0), G(4, 1), G(4, 0), cap='孙'),
                B(G(1, 0), G(1, 1), cap='晋'), B(G(0, 4), cap='马'))
Exemplo n.º 7
0
class Game7(Game):
    title = '井中之蛙'

    initial = L(B(G(1, 0), G(2, 0), cap='赵'), B(G(0, 1), cap='甲'),
                B(G(1, 1), G(2, 1), cap='张'), B(G(3, 1), cap='乙'),
                B(G(0, 2), G(0, 3), cap='马'),
                B(G(1, 2), G(2, 2), G(1, 3), G(2, 3), cap='曹'),
                B(G(3, 2), G(3, 3), cap='黄'), B(G(0, 4), cap='丙'),
                B(G(1, 4), G(2, 4), cap='关'), B(G(3, 4), cap='丁'))
Exemplo n.º 8
0
class Game99(Game):
    title = '逗逼三国'

    width = 5
    height = 5

    initial = L(
        B(G(1, 3), G(2, 3), G(1, 4), G(2, 4), cap='曹'),
        B(G(0, 2), G(0, 3), G(1, 2), G(1, 1), cap='刘'),
        B(G(3, 1), G(3, 2), G(4, 1), G(2, 1), G(3, 0), cap='孙'),
        # B(G(4, 3), cap='袁')
    )
Exemplo n.º 9
0
#!/usr/bin/env python
import rps
from players.human import Player as HP
from players.copycat import Player as CP
from players.random import Player as RP
from players.predict.simple import Player as SPP
from players.predict.anti_simple import Player as ASPP
from game import RPSGame as G
from tournament import RPSTournament as T

if __name__ == '__main__':
    rps.VERB = 1
    anti_simple_player = ASPP()
    simple_predict_player = SPP()
    my_game = G(anti_simple_player, simple_predict_player, steps=20)
    with my_game as game:
        game.run()
    print(my_game.winner())