chess: code reformatting

master
TiynGER 4 years ago
parent e30ff1f3ba
commit f749f66c3c

@ -343,7 +343,8 @@ proc gen_pawn_double_dests(game: Game, field: int, color: Color): seq[int] =
for doubles in Pawn_Moves_White_Double: for doubles in Pawn_Moves_White_Double:
dest = field + doubles * ord(color) dest = field + doubles * ord(color)
target = game.pieces.get_field(dest) target = game.pieces.get_field(dest)
if (game.moved.get_field(field) or (target != 0) or (game.pieces.get_field(dest+(S*ord(color))) != 0)): if (game.moved.get_field(field) or (target != 0) or (
game.pieces.get_field(dest+(S*ord(color))) != 0)):
continue continue
res.add(dest) res.add(dest)
return res return res
@ -380,8 +381,8 @@ proc piece_on(game: Game, color: Color, sequence: seq[int],
proc is_attacked(game: Game, position: int, color: Color): bool = proc is_attacked(game: Game, position: int, color: Color): bool =
## Check if a field is attacked by the opposite of `color` in a `game`. ## Check if a field is attacked by the opposite of `color` in a `game`.
var attacked = false var attacked = false
attacked = attacked or game.piece_on(color, game.gen_pawn_attack_dests(position, attacked = attacked or game.piece_on(color, game.gen_pawn_attack_dests(
color), PawnID) position, color), PawnID)
attacked = attacked or game.piece_on(color, game.gen_queen_dests(position, attacked = attacked or game.piece_on(color, game.gen_queen_dests(position,
color), QueenID) color), QueenID)
attacked = attacked or game.piece_on(color, game.gen_king_dests(position, attacked = attacked or game.piece_on(color, game.gen_king_dests(position,
@ -615,7 +616,8 @@ proc checked_move*(game: var Game, move: Move): bool {.discardable.} =
game.pieces.set_field(dest-(N*ord(color)), EnPassantID * ord(color)) game.pieces.set_field(dest-(N*ord(color)), EnPassantID * ord(color))
if captured_en_passant: if captured_en_passant:
game.pieces.set_field(dest-(N*ord(color)), 0) game.pieces.set_field(dest-(N*ord(color)), 0)
if ((90 < dest and dest < 99) or (20 < dest and dest < 29)) and game.pieces.get_field(dest) == PawnID * ord(color): if ((90 < dest and dest < 99) or (20 < dest and dest < 29)) and
game.pieces.get_field(dest) == PawnID * ord(color):
game.pieces.set_field(dest, prom) game.pieces.set_field(dest, prom)
return true return true
except IndexDefect, ValueError: except IndexDefect, ValueError:

Loading…
Cancel
Save