From 09973b6cde0590057b4737927226cb9526d2de9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Tue, 6 Mar 2018 11:43:10 +0100 Subject: [PATCH] =?UTF-8?q?(=E2=95=AF=C2=B0=E2=96=A1=C2=B0=EF=BC=89?= =?UTF-8?q?=E2=95=AF=EF=B8=B5=20=E2=94=BB=E2=94=81=E2=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- board.py | 5 +++-- test.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) 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()