コード例 #1
0
 def test_is_valid_obstructed(self):
     q = pc.Queen(3, 3)
     p = pc.Pawn(3, 4)
     b = board.Board()
     b.pieces.extend([q, p])
     self.assertTrue(move.Move(q, T(1, 1, 1)).is_valid(b))
     self.assertFalse(move.Move(q, T(0, 1, 2)).is_valid(b))
     self.assertFalse(move.Move(q, T(0, 1, 1)).is_valid(b))
コード例 #2
0
 def test_is_valid_capture(self):
     q = pc.Queen(3, 3)
     p = pc.Pawn(3, 4)
     r = pc.Rook(2, 3, True)
     b = board.Board()
     b.pieces.extend([q, p, r])
     self.assertTrue(move.Move(q, T(1, 1, 1)).is_valid(b))
     self.assertFalse(move.Move(q, T(0, 1, 1)).is_valid(b))
     self.assertTrue(move.Move(q, T(-1, 0, 1)).is_valid(b))
コード例 #3
0
 def test_negative_magnitude(self):
     p = pc.Pawn(5, 5, True)
     bo = board.Board()
     bo._clear_board()
     bo.pieces.append(p)
     m = move.Move(p, T(0, -1, 1))
     m.is_valid(bo)
     m.apply(bo)
     self.assertEqual(p.get_position()[0], 5)
     self.assertEqual(p.get_position()[1], 4)
コード例 #4
0
 def test_apply(self):
     b = pc.Bishop(5, 5)
     m = move.Move(b, T(-1, -1, 3))
     bo = board.Board()
     self.assertTrue(bo.to_play == bo.WHITE)
     m.is_valid(bo)
     m.apply(bo)
     self.assertTrue(bo.to_play == bo.BLACK)
     self.assertEqual(b.get_position()[0], 2)
     self.assertEqual(b.get_position()[1], 2)
     self.assertTrue(bo.get_piece_at(5, 5) is None)
コード例 #5
0
 def test_is_valid_board_limits(self):
     q = pc.Queen(0, 0)
     b = board.Board()
     # Remove initial board setup
     b.pieces = [q]
     self.assertTrue(move.Move(q, T(1, 1, 1)).is_valid(b))
     self.assertFalse(move.Move(q, T(-1, 1, 1)).is_valid(b))
     self.assertFalse(move.Move(q, T(1, -1, 1)).is_valid(b))
     n = pc.Knight(6, 6)
     self.assertTrue(move.Move(n, T(-2, 1, 1)).is_valid(b))
     self.assertFalse(move.Move(n, T(2, 1, 1)).is_valid(b))
     self.assertFalse(move.Move(n, T(-1, 2, 1)).is_valid(b))
コード例 #6
0
 def test_capture_value(self):
     q = pc.Queen(3, 3)
     p = pc.Pawn(3, 4)
     r = pc.Rook(2, 3, True)
     b = board.Board()
     b.pieces.extend([q, p, r])
     m1 = move.Move(q, T(1, 1, 1))
     self.assertTrue(m1.is_valid(b))
     self.assertEqual(m1.value(b), 0)
     self.assertFalse(move.Move(q, T(0, 1, 1)).is_valid(b))
     m2 = move.Move(q, T(-1, 0, 1))
     self.assertTrue(m2.is_valid(b))
     self.assertEqual(m2.value(b), 5)
コード例 #7
0
 def test_undo(self):
     b = pc.Bishop(5, 5)
     q = pc.Queen(6, 6, True)
     bo = board.Board()
     bo._clear_board()
     bo.pieces.append(b)
     bo.pieces.append(q)
     m = move.Move(b, T(1, 1, 1))
     m.is_valid(bo)
     self.assertTrue(bo.to_play == bo.WHITE)
     m.apply(bo)
     m.undo(bo)
     self.assertTrue(bo.to_play == bo.WHITE)
     self.assertEqual(b.get_position()[0], 5)
     self.assertEqual(b.get_position()[1], 5)
     self.assertEqual(bo.get_piece_at(6, 6), q)
コード例 #8
0
 def setUp(self):
     self.parser = parser.Parser()
     self.board = board.Board()
コード例 #9
0
ファイル: test_tree.py プロジェクト: tr325/ChessBot
 def setUp(self):
     self.tree = tree.Tree()
     self.new_board = b.Board()
コード例 #10
0
 def setUp(self):
     self.board = board.Board()
コード例 #11
0
 def test_new_board_move_counts(self):
     board = B.Board()
     for p in board.pieces:
         self.initial_move_counts(p, board)
コード例 #12
0
ファイル: test_naive.py プロジェクト: tr325/ChessBot
 def setUp(self):
     self.new_board = b.Board()
     self.naive = n.Naive()
コード例 #13
0
import readline
import engine.board as Board
import engine.tree as Tree
import interface.parser as Parser
import decision.naive as Naive

board = Board.Board()
tree = Tree.Tree()
tree.set_depth(2)
parser = Parser.Parser()
naive = Naive.Naive()
while (True):
    print(board.render())

    # User move (plays white)
    user_input = str(input("Play a move: "))
    move = parser.get_move(user_input, board)
    while (move is None):
        user_input = str(input("Sorry, that's not a valid move - try again: "))
        move = parser.get_move(user_input, board)
    move.apply(board)
    print(board.render())

    # Engine move (plays black)
    computer_move = naive.get_best_move(board)
    computer_move.apply(board)