Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding strategy tests

  • Loading branch information...
commit 365f8021493f3d4dde4d9d749b30dac270f8640b 1 parent 7a7cb76
@troynt authored
Showing with 106 additions and 1 deletion.
  1. +1 −0  strategy.py
  2. +105 −1 tests/strategy_test.py
View
1  strategy.py
@@ -2,6 +2,7 @@
from math import floor
from numpy import arange
import re
+from move import *
class Strategy:
def __init__(self, board):
View
106 tests/strategy_test.py
@@ -7,7 +7,7 @@
from starjeweled import *
from strategy import *
-class AiTestCase(unittest.TestCase):
+class StrategyTestCase(unittest.TestCase):
def setUp(self):
self.b = Board()
self.strategy = Strategy( self.b )
@@ -19,5 +19,109 @@ def testNoMovesFound(self):
self.b.setBoard("00b0b000" + ("0" * 7 * 8))
self.assertEqual(self.strategy.findMove(), None, 'checking no moves found')
+ def testHorizontalThree(self):
+ empty_row = list('0' * self.b.num_cols)
+ self.b.fromArray([
+ list('00000bb0'),
+ list('0000000b'),
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ ])
+ self.assertEqual(str(self.strategy.findMove()), '(7, 1) to (7, 0)')
+
+ self.b.fromArray([
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ list('00000bb0'),
+ list('0000000b'),
+ ])
+ self.assertEqual(str(self.strategy.findMove()), '(7, 7) to (7, 6)')
+
+ self.b.fromArray([
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ list('0000000b'),
+ list('b0000000'),
+ list('0b00000b'),
+ ])
+ self.assertEqual(self.strategy.findMove(), None)
+
+ self.b.fromArray([
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ list('b0b00000'),
+ list('0b000000'),
+ empty_row,
+ ])
+ self.assertEqual(str(self.strategy.findMove()), '(1, 6) to (1, 5)')
+
+ def testHorizontalFour(self):
+ #provide the opportunity for 3, but it should prefer the 4.
+ empty_row = list('0' * self.b.num_cols)
+ self.b.fromArray([
+ list('000000bb'),
+ list('00000b00'),
+ list('0000b0bb'),
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ ])
+ self.assertEqual(str(self.strategy.findMove()), '(5, 1) to (5, 2)')
+
+
+ def testVerticalThree(self):
+ empty_row = list('0' * self.b.num_cols)
+ self.b.fromArray([
+ list('0000000b'),
+ list('000000b0'),
+ list('0000000b'),
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ ])
+ self.assertEqual(str(self.strategy.findMove()), '(6, 1) to (7, 1)')
+
+ self.b.fromArray([
+ list('0000000b'),
+ list('0000000b'),
+ list('000000b0'),
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ ])
+ self.assertEqual(str(self.strategy.findMove()), '(6, 2) to (7, 2)')
+
+ self.b.fromArray([
+ list('0000000b'),
+ list('0000000b'),
+ empty_row,
+ list('b0000000'),
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ empty_row,
+ ])
+ self.assertEqual(self.strategy.findMove(), None)
if __name__ == '__main__':
unittest.main()
Please sign in to comment.
Something went wrong with that request. Please try again.