Initial
This commit is contained in:
commit
2ca7a264b3
53 files changed
+7113
No files matched your search
@@ -0,0 +1,28 @@
|
||||
"""Round-trip a local game at every decision, including pending choices."""
|
||||
import random
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.extend([str(ROOT / "game"), str(ROOT / "demo")])
|
||||
import local_game as local
|
||||
|
||||
|
||||
class BrowserSave(unittest.TestCase):
|
||||
def test_resumes_with_same_decisions(self):
|
||||
for bots in (3, 4, 5):
|
||||
rng = random.Random(bots)
|
||||
game = local.e.new_game(bots, rng=rng)
|
||||
for _ in range(3000):
|
||||
token = local.encode(game)
|
||||
self.assertLess(len(token), 3500)
|
||||
restored = local.decode(token)
|
||||
self.assertEqual(token, local.encode(restored))
|
||||
self.assertEqual(local.e.actions(game), local.e.actions(restored))
|
||||
if game["winner"] is not None:
|
||||
break
|
||||
view = local.e.observation(game, local.e.actor(game))
|
||||
choice = local.decide(dict(view=view, actions=local.e.actions(game)))
|
||||
local.e.Turn(game, lambda *_: None, rng).apply(choice["command"])
|
||||
self.assertIsNotNone(game["winner"])
|
||||
Reference in new issue
Block a user