online multiplayer chess game (note server currently down)
Diffstat (limited to 'pieces/King.gd')
-rw-r--r--pieces/King.gd40
1 files changed, 34 insertions, 6 deletions
diff --git a/pieces/King.gd b/pieces/King.gd
index c039f5b..2a96c70 100644
--- a/pieces/King.gd
+++ b/pieces/King.gd
@@ -20,12 +20,34 @@ func get_moves():
return moves
+func just_before_over(): # assign metadata for threefold repetition draw check
+ castleing()
+ if can_castle.size() > 0:
+ for i in can_castle:
+ if i[3] == "O-O-O":
+ if white:
+ Globals.grid.matrix[8].wccl = true
+ else:
+ Globals.grid.matrix[8].bccl = true
+ else:
+ if white:
+ Globals.grid.matrix[8].wccr = true
+ else:
+ Globals.grid.matrix[8].bccr = true
+
+
+func _ready():
+ Events.connect("just_before_turn_over", self, "just_before_over")
+
+
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)):
+ if !is_on_board(rooks[i]):
+ continue
var rook = at_pos(rooks[i])
if !rook is Rook:
continue
@@ -38,19 +60,25 @@ func castleing():
continue
if checkcheck(posx2) or checkcheck(pos):
continue
- can_castle.append([posx2, rook, rook_motion[i]])
+ can_castle.append([posx2, rook, rook_motion[i], "O-O-O" if i == 1 else "O-O"])
moves.append(posx2)
return moves
func castle(position):
+ var return_string = ""
+ if can_castle.size() == 1:
+ return_string = can_castle[0][3]
+ else:
+ for i in can_castle:
+ if i[0] == position:
+ return_string = i[3]
+ break
+ override_moveto = true
can_castle.clear()
moveto(position)
-
-
-func _ready():
- ._ready()
- shortname = "k" + team
+ override_moveto = false
+ return return_string
func can_move(): # checks if you can legally move