예제 #1
0
 def setUp(self):
     self.board = Board()
     self.board.move_if_legal("e2", "e4", "white")
     self.board.move_if_legal("e7", "e5", "black")
     self.board.move_if_legal("f1", "c4", "white")
     self.board.move_if_legal("b8", "c6", "black")
     self.board.move_if_legal("d1", "h5", "white")
     self.board.move_if_legal("g8", "c6", "black")
     self.board.move_if_legal("h5", "f7", "white")
예제 #2
0
from src.Chess2 import Board

board = Board()
color_to_move = "white"


def switch_turn(color):
    if color == "white":
        return "black"
    else:
        return "white"


print(board.display())
while not board.game_ended:

    move = input("Enter move in the form <from_square>,<to_square>:")
    from_square = move.split(",")[0]
    to_square = move.split(",")[1]
    if board.move_is_legal(from_square, to_square, color_to_move):
        board.move_if_legal(from_square, to_square, color_to_move)
        color_to_move = switch_turn(color_to_move)
        print("")
        print(board.display())
    else:
        print("illegal move!")
else:
    print(board.result)
예제 #3
0
 def setUp(self):
     self.board = Board()
예제 #4
0
 def setUp(self):
     self.board = Board()
     for square in square_names:
         setattr(self.board, square, "empty")
     self.board.put("a1", "white king")
     self.board.put("b3", "black queen")
예제 #5
0
 def test_countLegalMoves_inInitialPosition(self):
     self.board = Board()
     self.assertEqual(20, self.board.count_legal_moves("white"))
     self.assertEqual(20, self.board.count_legal_moves("black"))
예제 #6
0
 def setUp(self):
     self.board = Board()
     self.board.move_if_legal("f2", "f3", "white")
     self.board.move_if_legal("e7", "e5", "black")
     self.board.move_if_legal("g2", "g4", "white")
     self.board.move_if_legal("d8", "h4", "black")
예제 #7
0
 def setUp(self):
     self.board = Board()
     self.board.put("white king", "a3")
     self.board.put("black king", "h6")
     self.board.free_square("e1")
     self.board.free_square("e8")
예제 #8
0
 def setUp(self):
     self.board = Board()
     self.board.put("white king", "a3")
     self.board.put("black king", "h6")
예제 #9
0
 def setUp(self):
     self.board = Board()
     self.board.put("white queen", "a3")
     self.board.put("black queen", "h6")
예제 #10
0
 def setUp(self):
     self.board = Board()
     self.board.put("white knight", "e5")
     self.board.put("black knight", "d3")
예제 #11
0
 def test_bishopCanMoveFromInitialPos(self):
     self.board = Board()
     self.board.move("e2", "e3")
     self.assertTrue(self.board.is_reachable("f1", "c4", "white"))
예제 #12
0
 def setUp(self):
     self.board = Board()
     self.board.put("white bishop", "a3")
     self.board.put("black bishop", "a6")
예제 #13
0
 def setUp(self):
     self.board = Board()
     self.board.put("white rook", "a3")
     self.board.put("black rook", "h6")