online multiplayer chess game (note server currently down)
Diffstat (limited to 'pieces/King.gd')
| -rw-r--r-- | pieces/King.gd | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/pieces/King.gd b/pieces/King.gd index cfc7ade..68b1183 100644 --- a/pieces/King.gd +++ b/pieces/King.gd @@ -5,11 +5,11 @@ var castle_check := true var can_castle := [] -func _ready(): +func _ready() -> void: Events.connect("just_before_turn_over", self, "just_before_over") -func get_moves(): +func get_moves() -> Array: var moves := [] for i in all_dirs(): var spot: Vector2 = pos_around(i) @@ -19,12 +19,12 @@ func get_moves(): if check_spots_check and checkcheck(spot): continue moves.append(spot) - if castle_check and !has_moved and !Globals.in_check: # make sure this is only called when clicking + if castle_check and !Globals.in_check: # make sure this is only called when clicking moves.append_array(castleing()) return moves -func just_before_over(): # assign metadata for threefold repetition draw check +func just_before_over() -> void: # assign metadata for threefold repetition draw check castleing() if can_castle.size() > 0: for i in can_castle: @@ -40,9 +40,12 @@ func just_before_over(): # assign metadata for threefold repetition draw check Globals.grid.matrix[8].bccr = true -func castleing(): +func castleing(justcheckrooks = false) -> Array: + if has_moved: + return [] var moves := [] var rooks := [pos_around(Vector2.RIGHT * 3), pos_around(Vector2.LEFT * 4)] + var labels = ["Q", "K"] var rook_motion := [pos_around(Vector2.RIGHT), pos_around(Vector2.LEFT)] var king_moveto_spots := [Vector2.RIGHT, Vector2.LEFT] # O-O and O-O-O respectivel for i in range(len(rooks)): @@ -53,6 +56,9 @@ func castleing(): continue if rook.has_moved: continue + if justcheckrooks: + moves.append(labels[i]) + continue var direction: Vector2 = king_moveto_spots[i] var posx2: Vector2 = pos_around(direction * 2) var pos: Vector2 = pos_around(direction) @@ -65,7 +71,7 @@ func castleing(): return moves -func castle(position): +func castle(position) -> String: var return_string = "" if can_castle.size() == 1: return_string = can_castle[0][3] @@ -81,14 +87,14 @@ func castle(position): return return_string -func can_move(): # checks if you can legally move +func can_move() -> bool: # checks if you can legally move castle_check = false var can: bool = .can_move() castle_check = true return can -func get_attacks(): +func get_attacks() -> Array: castle_check = false var final: Array = .get_attacks() castle_check = true |