online multiplayer chess game (note server currently down)
-rw-r--r--pieces/King.gd21
-rw-r--r--pieces/Piece.gd4
2 files changed, 14 insertions, 11 deletions
diff --git a/pieces/King.gd b/pieces/King.gd
index 4c2c9d1..8f4ce4b 100644
--- a/pieces/King.gd
+++ b/pieces/King.gd
@@ -4,18 +4,21 @@ class_name King
func get_moves():
var moves = [
- .pos_around(Vector2.UP),
- .pos_around(Vector2.DOWN),
- .pos_around(Vector2.LEFT),
- .pos_around(Vector2.RIGHT),
- .pos_around(Vector2(1, 1)),
- .pos_around(Vector2(1, -1)),
- .pos_around(Vector2(-1, 1)),
- .pos_around(Vector2(-1, -1))
+ pos_around(Vector2.UP),
+ pos_around(Vector2.DOWN),
+ pos_around(Vector2.LEFT),
+ pos_around(Vector2.RIGHT),
+ pos_around(Vector2(1, 1)),
+ pos_around(Vector2(1, -1)),
+ pos_around(Vector2(-1, 1)),
+ pos_around(Vector2(-1, -1))
]
var final = []
for i in moves:
- if .is_on_board(i):
+ if is_on_board(i):
+ if check_spots_check:
+ if !checkcheck(i):
+ continue
final.append(i)
return final
diff --git a/pieces/Piece.gd b/pieces/Piece.gd
index 5c10d2b..8e5dfbb 100644
--- a/pieces/Piece.gd
+++ b/pieces/Piece.gd
@@ -145,13 +145,13 @@ func set_circle(positions: Array, type := "move"):
create_take_circles(spot) # if the king is in check, return true
-func checkcheck(pos): # moves to position, then checks if your king is in check
+func checkcheck(pos): # moves to position, then checks if your king is not in check
if Globals.in_check: # if you are in check
var mat = Globals.grid.matrix.duplicate(true) # make a copy of the matrix
moveto(pos, false) # move to the position
print("moved " + shortname + " to " + str(pos))
var retu = true # return true by default
- if !Globals.grid.check_in_check(): # if you are still in check
+ if Globals.grid.check_in_check(): # if you are still in check
print("did not fix check") # sadge
retu = false # return false, but fix the matrix first
# Globals.grid.print_matrix_pretty(mat) # print the matrix