small fixes
parent
e68196be39
commit
8256ba1bf6
34
chess.py
34
chess.py
|
@ -11,14 +11,18 @@ ranks = "87654321"
|
|||
files = "abcdefgh"
|
||||
squares = cross(files, ranks)
|
||||
|
||||
pawn_ranks = "27"
|
||||
home_ranks = "18"
|
||||
init_positions = {"pawn" : cross(files, pawn_ranks),
|
||||
"rook" : cross("ah", home_ranks),
|
||||
"knight" : cross("bg", home_ranks),
|
||||
"bishop" : cross("cf", home_ranks),
|
||||
"queen" : cross("d", home_ranks),
|
||||
"king" : cross("e", home_ranks)
|
||||
pawn_ranks = {"white" : '2',
|
||||
"black" : '7'
|
||||
}
|
||||
home_ranks = {"white" : '1',
|
||||
"black" : '8'
|
||||
}
|
||||
init_positions = {"pawn" : cross(files, pawn_ranks.values()),
|
||||
"rook" : cross("ah", home_ranks.values()),
|
||||
"knight" : cross("bg", home_ranks.values()),
|
||||
"bishop" : cross("cf", home_ranks.values()),
|
||||
"queen" : cross("d", home_ranks.values()),
|
||||
"king" : cross("e", home_ranks.values())
|
||||
}
|
||||
|
||||
AN_names = {'R' : "rook",
|
||||
|
@ -27,12 +31,6 @@ AN_names = {'R' : "rook",
|
|||
'Q' : "queen",
|
||||
'K' : "king"}
|
||||
|
||||
def get_rank(sq):
|
||||
return int(sq[1])
|
||||
|
||||
def get_file(sq):
|
||||
return sq[0]
|
||||
|
||||
def move(sq, v):
|
||||
return chr(ord(sq[0]) + v[0]) + str(int(sq[1]) + v[1])
|
||||
|
||||
|
@ -208,9 +206,7 @@ class Game:
|
|||
|
||||
if frwd in squares and is_empty(frwd):
|
||||
r.append(frwd)
|
||||
is_on_pawn_rank = color == "white" and get_rank(sq)==2 \
|
||||
or \
|
||||
color == "black" and get_rank(sq)==7
|
||||
is_on_pawn_rank = pawn_ranks[color] == sq[1]
|
||||
if is_on_pawn_rank and is_empty(jump):
|
||||
r.append(jump)
|
||||
return r + [sq for sq in targets if can_eat(sq)]
|
||||
|
@ -269,7 +265,7 @@ def test():
|
|||
game = Game()
|
||||
assert len(squares) == 8**2
|
||||
assert sum(map(len, init_positions.values())) == 8*4
|
||||
moves = [("a2", "a3"), ("b1", "c3"), ("c3", "b5"), ("b8", "c6")]
|
||||
moves = [("a2", "a4"), ("b1", "c3"), ("c3", "b5"), ("b8", "c6")]
|
||||
for m in moves:
|
||||
game.move(*m)
|
||||
print (game)
|
||||
|
@ -280,3 +276,5 @@ def test():
|
|||
print(game.possible_moves("c3"))
|
||||
print(game.is_attacked("black", "d8"))
|
||||
|
||||
|
||||
test()
|
||||
|
|
Loading…
Reference in New Issue