chess: code reformatting

master
TiynGER 4 years ago
parent e30ff1f3ba
commit f749f66c3c

@ -269,7 +269,7 @@ proc gen_king_castle_dest(game: Game, field: int, color: Color): seq[int] =
for castle in King_Moves_White_Castle: for castle in King_Moves_White_Castle:
dest = field + castle dest = field + castle
target = game.pieces.get_field(dest) target = game.pieces.get_field(dest)
half_dest = field + (int) castle/2 half_dest = field + (int)castle/2
half_target = game.pieces.get_field(half_dest) half_target = game.pieces.get_field(half_dest)
if (target == 999 or (target != 0)): if (target == 999 or (target != 0)):
continue continue
@ -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,
@ -429,7 +430,7 @@ proc remove_en_passant(pieces: var Pieces, color: Color): void =
## Removes every en passant of given `color` from the `game`. ## Removes every en passant of given `color` from the `game`.
for field in pieces.low..pieces.high: for field in pieces.low..pieces.high:
if pieces.get_field(field) == ord(color) * EnPassantID: if pieces.get_field(field) == ord(color) * EnPassantID:
pieces.set_field(field,0) pieces.set_field(field, 0)
proc gen_legal_knight_moves(game: Game, field: int, color: Color): seq[Move] = proc gen_legal_knight_moves(game: Game, field: int, color: Color): seq[Move] =
## Generates all legal knight moves starting from `field` in a `game` for a `color`. ## Generates all legal knight moves starting from `field` in a `game` for a `color`.
@ -599,7 +600,7 @@ proc checked_move*(game: var Game, move: Move): bool {.discardable.} =
var move: Move var move: Move
move = get_move(start, dest, color) move = get_move(start, dest, color)
if (piece == PawnID * ord(color)): if (piece == PawnID * ord(color)):
create_en_passant = dest in game.gen_pawn_double_dests(start,color) create_en_passant = dest in game.gen_pawn_double_dests(start, color)
captured_en_passant = (game.pieces.get_field(dest) == -1 * ord(color) * EnPassantID) captured_en_passant = (game.pieces.get_field(dest) == -1 * ord(color) * EnPassantID)
sequence.add(game.gen_legal_moves(start, color)) sequence.add(game.gen_legal_moves(start, color))
if (move in sequence): if (move in sequence):
@ -612,10 +613,11 @@ proc checked_move*(game: var Game, move: Move): bool {.discardable.} =
game.unchecked_move(start, dest) game.unchecked_move(start, dest)
game.to_move = Color(ord(game.to_move)*(-1)) game.to_move = Color(ord(game.to_move)*(-1))
if create_en_passant: if create_en_passant:
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