diff --git a/board.py b/board.py index 592f80e..349e3ff 100644 --- a/board.py +++ b/board.py @@ -1,4 +1,3 @@ -import pdb import numpy as np import itertools @@ -271,4 +270,6 @@ class Board: return tuple(board) - + @staticmethod + def flip(board): + return tuple((-x for x in reversed(board))) diff --git a/test.py b/test.py index 260c8bd..8e7cca6 100644 --- a/test.py +++ b/test.py @@ -551,6 +551,60 @@ class TestLegalMoves(unittest.TestCase): } self.assertEqual(Board.calculate_legal_states(board, -1, (4,3)), expected_board_set) + +class TestBoardFlip(unittest.TestCase): + def test_flip_board(self): + board = (0, + -14, -1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, + 0) + + expected_board = ( 0, + -1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 14, + 0 ) + + self.assertEqual(Board.flip(board), expected_board) + + def test_flip_board_bar(self): + board = (2, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + -7) + + expected_board = (7, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + -2) + + self.assertEqual(Board.flip(board), expected_board) + + def test_flip_board_extensive(self): + board = (4, + -5, -1, 0, 4, 3, 0, + 0, -1, 0, -5, 0, 0, + 0, 3, 0, 0, 0, 0, + 0, 0, 0, -1, 0, 1, + -2) + + expected_board = (2, + -1, 0, 1, 0, 0, 0, + 0, 0, 0, 0, -3, 0, + 0, 0, 5, 0, 1, 0, + 0, -3, -4, 0, 1, 5, + -4) + + self.assertEqual(Board.flip(board), expected_board) + + if __name__ == '__main__': unittest.main()