online multiplayer chess game (note server currently down)
Diffstat (limited to 'pieces/King.gd')
-rw-r--r--pieces/King.gd61
1 files changed, 29 insertions, 32 deletions
diff --git a/pieces/King.gd b/pieces/King.gd
index 465a8e0..1bd4487 100644
--- a/pieces/King.gd
+++ b/pieces/King.gd
@@ -16,24 +16,30 @@ func get_moves():
continue
moves.append(spot)
if castle_check and !has_moved and !Globals.in_check: # make sure this is only called when clicking
- var rooks = [pos_around(Vector2.RIGHT * 3), pos_around(Vector2.LEFT * 4)]
- 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)):
- var rook = at_pos(rooks[i])
- if !rook is Rook:
- continue
- if rook.has_moved:
- continue
- var direction = king_moveto_spots[i]
- var posx2 = pos_around(direction * 2)
- var pos = pos_around(direction)
- if at_pos(posx2) or at_pos(pos):
- continue
- if checkcheck(posx2) or checkcheck(pos):
- continue
- can_castle.append([posx2, rook, rook_motion[i]])
- moves.append(posx2)
+ moves.append_array(castleing())
+ return moves
+
+
+func castleing():
+ var moves = []
+ var rooks = [pos_around(Vector2.RIGHT * 3), pos_around(Vector2.LEFT * 4)]
+ 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)):
+ var rook = at_pos(rooks[i])
+ if !rook is Rook:
+ continue
+ if rook.has_moved:
+ continue
+ var direction = king_moveto_spots[i]
+ var posx2 = pos_around(direction * 2)
+ var pos = pos_around(direction)
+ if at_pos(posx2) or at_pos(pos):
+ continue
+ if checkcheck(posx2) or checkcheck(pos):
+ continue
+ can_castle.append([posx2, rook, rook_motion[i]])
+ moves.append(posx2)
return moves
@@ -49,22 +55,13 @@ func _ready():
func can_move(): # checks if you can legally move
castle_check = false
- if get_moves().size() != 0 or get_attacks().size() != 0:
- castle_check = true
- return true
- castle_check = false
- return false
+ var can = can_move()
+ castle_check = true
+ return can
-func get_attacks(): # @Override
+func get_attacks():
castle_check = false
- var moves = get_moves() # assumes the attacks are same as moves
- var final = []
- for i in moves:
- if at_pos(i) != null:
- if at_pos(i).white != white: # attack ze enemie
- if check_spots_check and checkcheck(i):
- continue
- final.append(i)
+ var final = .get_attacks()
castle_check = true
return final