online multiplayer chess game (note server currently down)
-rw-r--r--pieces/King.gd2
-rw-r--r--pieces/Knight.gd2
-rw-r--r--pieces/Pawn.gd2
-rw-r--r--pieces/Piece.gd19
4 files changed, 11 insertions, 14 deletions
diff --git a/pieces/King.gd b/pieces/King.gd
index b50bd2e..a5b44d2 100644
--- a/pieces/King.gd
+++ b/pieces/King.gd
@@ -7,7 +7,7 @@ func get_moves():
for i in all_dirs():
var spot = pos_around(i)
if is_on_board(spot):
- if check_spots_check and checkcheck(spot):
+ if check_spots_check and Globals.in_check and checkcheck(spot):
continue
moves.append(spot)
return moves
diff --git a/pieces/Knight.gd b/pieces/Knight.gd
index 477afec..b973f06 100644
--- a/pieces/Knight.gd
+++ b/pieces/Knight.gd
@@ -16,7 +16,7 @@ func get_moves():
var final = []
for i in moves:
if is_on_board(i):
- if check_spots_check and checkcheck(i):
+ if check_spots_check and Globals.in_check and checkcheck(i):
continue
final.append(i)
return final
diff --git a/pieces/Pawn.gd b/pieces/Pawn.gd
index 7760913..5c232ae 100644
--- a/pieces/Pawn.gd
+++ b/pieces/Pawn.gd
@@ -13,7 +13,7 @@ func get_moves():
if at_pos(point) == null:
if i == 1 and has_moved or at_pos(pos_around(points[0] * whiteint)) != null:
continue
- if check_spots_check and checkcheck(point):
+ if check_spots_check and Globals.in_check and checkcheck(point):
continue
if is_on_board(point):
moves.append(point)
diff --git a/pieces/Piece.gd b/pieces/Piece.gd
index bc9068f..89d2b0c 100644
--- a/pieces/Piece.gd
+++ b/pieces/Piece.gd
@@ -49,7 +49,6 @@ func move(newpos: Vector2): # dont use directly; use moveto
)
anim.play("Move")
tween.start()
- # global_position = newpos * Globals.grid.piece_size
func moveto(position, real = true):
@@ -88,7 +87,8 @@ func traverse(arr = [Vector2.UP, Vector2.DOWN, Vector2.LEFT, Vector2.RIGHT]):
if at_pos(pos) != null: # only one black
circle_array.append(pos)
break
- if check_spots_check and checkcheck(pos):
+ if check_spots_check and Globals.in_check and checkcheck(pos):
+ print(checkcheck(pos))
continue
circle_array.append(pos)
return circle_array
@@ -140,16 +140,13 @@ func set_circle(positions: Array, type := "move"):
func checkcheck(pos): # moves to position, then checks if your king is 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
- var retu = false # return true by default
- if Globals.grid.check_in_check(): # if you are still in check
- retu = true # return false, but fix the matrix first
- # Globals.grid.print_matrix_pretty(mat) # print the matrix
+ var mat = Globals.grid.matrix.duplicate(true) # make a copy of the matrix
+ moveto(pos, false) # move to the position
+ if Globals.grid.check_in_check(): # if you are still in check
Globals.grid.matrix = mat # revert changes on the matrix
- return retu
- return false
+ return false
+ Globals.grid.matrix = mat # revert changes on the matrix
+ return true
func is_on_board(vector: Vector2):