Finished rolling stone playfield generation.

This commit is contained in:
Niels Serup
2012-08-08 11:07:33 +02:00
parent 2457f743cc
commit 6c050f954b
4 changed files with 184 additions and 153 deletions

View File

@@ -1,31 +1,39 @@
from __future__ import print_function
import unittest
from robotgame.logic.rollingstone import *
from robotgame.logic.direction import *
playfield_example_succeed = [
[Start(Down), None, None, None ],
[None, None, Stone(), None ],
[Turn(Right), None, Turn(Down), None ],
[None, Stone(), Turn(Right), Goal()],
]
playfield_example_fail = [
[Start(Down), None, None, None ],
[None, None, Stone(), None ],
[Turn(Right), Stone(), Turn(Down), None ],
[None, None, Turn(Right), Goal()],
]
class RollingStoneTest(unittest.TestCase):
def test_playfield(self):
self.assertTrue(reaches_goal(playfield_example_succeed, 100))
self.assertFalse(reaches_goal(playfield_example_fail, 100))
playfield_example_succeed = {
(0, 0): Down,
(0, 2): Right,
(1, 3): Stone,
(2, 1): Stone,
(2, 2): Down,
(2, 3): Right,
}
self.assertTrue(reaches_goal(playfield_example_succeed,
4, 4, 100, (0, 0), (3, 3)))
playfield_example_succeed[(1, 2)] = Stone
self.assertFalse(reaches_goal(playfield_example_succeed,
4, 4, 100, (0, 0), (3, 3)))
def test_playfield_generation(self):
playfield, min_steps = generate_playfield(10, 10, (0, 0), Down, (9, 9), 10, 5)
# self.assertTrue(reaches_goal(playfield, min_steps))
print()
playfield, steps = generate_simple_playfield(10, 10, 100, 100)
print_playfield(playfield, 10, 10, True)
self.assertTrue(
reaches_goal(playfield, 10, 10, steps, (0, 0), (9, 9)))
print()
playfield, steps = generate_simple_playfield(10, 10, 7, 20)
print_playfield(playfield, 10, 10, True)
self.assertTrue(
reaches_goal(playfield, 10, 10, steps, (0, 0), (9, 9)))
if __name__ == '__main__':
unittest.main()