示例#1
0
 def test_constructor_named(self):
     """Constructor with kw args works."""
     b = cs.Board()
     s = cs.Simulation(player_field=[cs.Player, cs.Player],
                       board=b,
                       seed=123,
                       randomize_players=True)
     assert isinstance(s, cs.Simulation)
 def test_single_game(self):
     player_list = [cs.Player, cs.Player, cs.Player]
     b = cs.Board()
     play = cs.Simulation(board=b, player_field=player_list)
     res = play.single_game()
     assert not res[1] == 'LazyPlayer'
     assert not res[1] == 'ResilientPlayer'
     assert res[1] == 'Player'
     assert isinstance(res[0], int)
 def test_durations_per_type(self):
     player_list = [
         cs.Player, cs.Player, cs.Player, cs.LazyPlayer, cs.LazyPlayer,
         cs.ResilientPlayer
     ]
     b = cs.Board()
     pl = cs.Simulation(board=b, player_field=player_list)
     pl.run_simulation(10)
     pl.get_results()
     res = pl.durations_per_type()
     for i in range(3):
         assert list(
             res.keys())[i] in ['Player', 'ResilientPlayer', 'LazyPlayer']
     for value in res.values():
         assert isinstance(value, list)
 def test_players_per_type(self):
     player_list = [
         cs.Player, cs.Player, cs.Player, cs.LazyPlayer, cs.LazyPlayer,
         cs.ResilientPlayer
     ]
     b = cs.Board()
     pl = cs.Simulation(board=b,
                        player_field=player_list,
                        randomize_players=False)
     pl.run_simulation(10)
     pl.get_results()
     res = pl.players_per_type()
     for i in range(3):
         assert list(
             res.keys())[i] in ['Player', 'ResilientPlayer', 'LazyPlayer']
     assert list(res.values())[0] == 3
     assert list(res.values())[1] == 2
     assert list(res.values())[2] == 1
 def test_move(self):
     b = cs.Board(ladders={
         1: 30,
         2: 31,
         3: 32,
         4: 33,
         5: 34,
         6: 35
     },
                  chutes={
                      40: 12,
                      41: 11,
                      42: 10,
                      43: 9
                  })
     p = cs.Player(b)
     pos1 = p.position
     p.move()
     pos2 = p.position
     assert pos1 is not pos2
     assert pos2 - pos1 >= 30
     assert pos2 >= 1
     assert not p.get_position() in b.ladders.keys()
     assert not p.get_position() in b.chutes.keys()
示例#6
0
 def test_constructor(self):
     """LazyPlayer can be constructed."""
     b = cs.Board()
     p = cs.LazyPlayer(b, dropped_steps=3)
     assert isinstance(p, cs.LazyPlayer)
     assert isinstance(p, cs.Player)
示例#7
0
 def test_move(self):
     """ResilientPlayer can move."""
     b = cs.Board()
     p = cs.ResilientPlayer(b)
     p.move()
示例#8
0
 def test_constructor(self):
     """ResilientPlayer can be created."""
     b = cs.Board()
     p = cs.ResilientPlayer(b, extra_steps=4)
     assert isinstance(p, cs.ResilientPlayer)
     assert isinstance(p, cs.Player)
示例#9
0
 def test_move(self):
     """Player has move() method."""
     b = cs.Board()
     p = cs.Player(b)
     p.move()
示例#10
0
 def test_constructor(self):
     """Player can be constructed."""
     b = cs.Board()
     p = cs.Player(b)
     assert isinstance(p, cs.Player)
示例#11
0
 def test_position_adjustment(self):
     """position_adjustment callable and returns number"""
     b = cs.Board()
     assert isinstance(b.position_adjustment(1), (int, float))
 def test_get_position(self):
     b = cs.Board()
     p = cs.Player(b)
     p.move()
     assert p.get_position() is p.position
示例#13
0
 def test_constructor_named_args(self):
     """Constructor with kw args callable."""
     b = cs.Board(ladders=[(1, 4), (5, 16)],
                  chutes=[(9, 2), (12, 3)],
                  goal=90)
     assert isinstance(b, cs.Board)
 def test_goal_reach_fail(self):
     board = cs.Board()
     assert not board.goal_reached(70)
示例#15
0
 def test_constructor_default(self):
     """Default constructor callable."""
     b = cs.Board()
     assert isinstance(b, cs.Board)
 def test_goal_reach_custom_goal(self):
     board = cs.Board(goal=100)
     assert not board.goal_reached(90)
     assert board.goal_reached(100)
 def test_goal_reach_success(self):
     board = cs.Board()
     assert board.goal_reached(90)
 def test_position_adjustment(self):
     b = cs.Board()
     assert b.position_adjustment(1) is 39
 def test_get_steps(self):
     b = cs.Board()
     p = cs.Player(b)
     p.move()
     p.move()
     assert p.get_steps() is 2
示例#20
0
 def test_move(self):
     """LazyPlayer can move."""
     b = cs.Board()
     p = cs.LazyPlayer(b)
     p.move()
示例#21
0
 def test_constructor_args(self):
     """Constructor with unnamed arguments callable."""
     b = cs.Board([(1, 4), (5, 16)], [(9, 2), (12, 3)], 90)
     assert isinstance(b, cs.Board)
示例#22
0
 def test_goal_reached(self):
     """goal_reached() callable and returns bool"""
     b = cs.Board()
     assert isinstance(b.goal_reached(1), bool)