예제 #1
0
 def reset_to_initial_locations(self):
     self.clear()
     for position, value in START_PIECES_POSITION.items():
         self[position] = pieces.create_piece(
             value)  # color argument is added just for testing
         #self[position].keep_reference(self)
     self.player_turn = 'white'
    def test_bogus_piece(self):
        failed_correctly = False
        try:
            piece = create_piece('checker')
        except PieceNotFoundError:
            failed_correctly = True

        assert failed_correctly, "Created nonexistent piece!"
예제 #3
0
 def process_notation(self, patt):
     patt = patt.split(' ')
     # expand_whitespaces blanks
     def expand_whitespaces(match): return ' ' * int(match.group(0))
     patt[0] = re.compile(r'\d').sub(expand_whitespaces, patt[0])
     for x, row in enumerate(patt[0].split('/')):
         for y, alphabet in enumerate(row):
             if alphabet == ' ': continue
             xycoord = self.alpha_notation((7-x,y))
             self[xycoord] = pieces.create_piece(alphabet)
             self[xycoord].ref(self)
     if patt[1] == 'w': self.player_turn = 'white'
     else: self.player_turn = 'black'
예제 #4
0
 def process_notation(self, patt):
     patt = patt.split(' ')
     # expand_whitespaces blanks
     def expand_whitespaces(match): return ' ' * int(match.group(0))
     patt[0] = re.compile(r'\d').sub(expand_whitespaces, patt[0])
     for x, row in enumerate(patt[0].split('/')):
         for y, alphabet in enumerate(row):
             if alphabet == ' ': continue
             xycoord = self.alpha_notation((7-x,y))
             self[xycoord] = pieces.create_piece(alphabet)
             self[xycoord].ref(self)
     if patt[1] == 'w': self.player_turn = 'white'
     else: self.player_turn = 'black'
예제 #5
0
 def show(self, pat):
     self.clear()
     pat = pat.split(' ')
     def expand(match): return ' ' * int(match.group(0))
     pat[0] = re.compile(r'\d').sub(expand, pat[0])
     for x, row in enumerate(pat[0].split('/')):
         for y, letter in enumerate(row):
             if letter == ' ': continue
             coord = self.alpha_notation((7-x,y))
             self[coord] = pieces.create_piece(letter)
             self[coord].place(self)
     if pat[1] == 'w': self.player_turn = 'white'
     else: self.player_turn = 'black'
     self.halfmove_clock = int(pat[2])
     self.fullmove_number = int(pat[3])
예제 #6
0
 def show(self, pat):
     self.clear()
     pat = pat.split(' ')
     def expand(match): return ' ' * int(match.group(0))
     pat[0] = re.compile(r'\d').sub(expand, pat[0])
     for x, row in enumerate(pat[0].split('/')):
         for y, letter in enumerate(row):
             if letter == ' ': continue
             coord = self.alpha_notation((7-x,y))
             self[coord] = pieces.create_piece(letter)
             self[coord].place(self)
     if pat[1] == 'w': self.player_turn = 'white'
     else: self.player_turn = 'black'
     self.halfmove_clock = int(pat[2])
     self.fullmove_number = int(pat[3])
예제 #7
0
import argparse
from pieces import Board, create_piece

parser = argparse.ArgumentParser()
parser.add_argument('-piece', dest='piece', required=True,
                    help='The piece to move')
parser.add_argument('-position', dest='position', required=True,
                    help='The starting position of the piece')
args = parser.parse_args()

position = args.position.lower()
# Instantiate the piece's class from user input
piece = create_piece(args.piece.lower())

board = Board()
# The board has-a piece
board.place_piece(piece, position)

# The board tells us the possible moves
possible_moves = board.list_possible_moves(piece)

print("Moves for {} at {}:".format(piece.name, position))
print(", ".join(possible_moves))
 def test_pieces_by_name(self):
     for piece in ('knight', 'queen', 'rook'):
         create_piece(piece)