This repository has been archived by the owner on Sep 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_othello_gameplay.py
110 lines (92 loc) · 3.43 KB
/
test_othello_gameplay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import unittest
import othello
class TestOthelloGameplay(unittest.TestCase):
def test_gameplay(self):
game = othello.Game()
rep = ('........',
'........',
'........',
'...OX...',
'...XO...',
'........',
'........',
'........')
self.assertEqual(tuple(game.state.board.repr), rep)
self.assertSetEqual(
set(game.state.get_legal_actions(othello.Player.DARK)),
{othello.Action(othello.Coords.from_repr(a))
for a in ('d3', 'c4', 'f5', 'e6')})
game.play(othello.Player.DARK,
othello.Action(othello.Coords.from_repr('d3')))
rep = ('........',
'........',
'...X....',
'...XX...',
'...XO...',
'........',
'........',
'........')
self.assertEqual(tuple(game.state.board.repr), rep)
self.assertSetEqual(
set(game.state.get_legal_actions(othello.Player.LIGHT)),
{othello.Action(othello.Coords.from_repr(a))
for a in ('c3', 'e3', 'c5')})
game.play(othello.Player.LIGHT,
othello.Action(othello.Coords.from_repr('c5')))
rep = ('........',
'........',
'...X....',
'...XX...',
'..OOO...',
'........',
'........',
'........')
self.assertEqual(tuple(game.state.board.repr), rep)
def test_endgame_1(self):
rep = ('OOOOOOOO',
'OOOOOOOO',
'OOOOOOOO',
'OOOOOOO.',
'OOOOOO..',
'OOOOOO.X',
'OOOOOOO.',
'OOOOOOOO')
state = othello.State(othello.Board.from_repr(rep))
self.assertSetEqual(set(state.get_legal_actions(othello.Player.DARK)),
set())
self.assertSetEqual(set(state.get_legal_actions(othello.Player.LIGHT)),
set())
self.assertIs(othello.Game(state).get_conclusion(),
othello.Player.LIGHT)
def test_endgame_2(self):
rep = ('.XXXXXXX',
'.OOOOO.X',
'OOOOOOOX',
'OOOOOOOX',
'OOOOOOOX',
'OOOOOOOX',
'OOOOOOOX',
'.OOOOOO.')
state = othello.State(othello.Board.from_repr(rep))
self.assertSetEqual(set(state.get_legal_actions(othello.Player.DARK)),
set())
self.assertSetEqual(set(state.get_legal_actions(othello.Player.LIGHT)),
set())
self.assertIs(othello.Game(state).get_conclusion(),
othello.Player.LIGHT)
def test_endgame_3(self):
rep = ('....O...',
'....OO..',
'OOOOOOOX',
'..OOOO.X',
'..OOO..X',
'........',
'........',
'........')
state = othello.State(othello.Board.from_repr(rep))
self.assertSetEqual(set(state.get_legal_actions(othello.Player.DARK)),
set())
self.assertSetEqual(set(state.get_legal_actions(othello.Player.LIGHT)),
set())
self.assertIs(othello.Game(state).get_conclusion(),
othello.Player.LIGHT)