online multiplayer chess game (note server currently down)
make it fully work! hurrah!
bendn 2022-04-27
parent 4564679 · commit 81e6be7
-rw-r--r--pieces/King.gd26
-rw-r--r--pieces/Knight.gd5
-rw-r--r--pieces/Pawn.gd5
-rw-r--r--pieces/Piece.gd20
4 files changed, 18 insertions, 38 deletions
diff --git a/pieces/King.gd b/pieces/King.gd
index 8f4ce4b..b50bd2e 100644
--- a/pieces/King.gd
+++ b/pieces/King.gd
@@ -3,24 +3,14 @@ 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))
- ]
- var final = []
- for i in moves:
- if is_on_board(i):
- if check_spots_check:
- if !checkcheck(i):
- continue
- final.append(i)
- return final
+ var moves = []
+ for i in all_dirs():
+ var spot = pos_around(i)
+ if is_on_board(spot):
+ if check_spots_check and checkcheck(spot):
+ continue
+ moves.append(spot)
+ return moves
func _ready():
diff --git a/pieces/Knight.gd b/pieces/Knight.gd
index 2ba7277..477afec 100644
--- a/pieces/Knight.gd
+++ b/pieces/Knight.gd
@@ -16,9 +16,8 @@ func get_moves():
var final = []
for i in moves:
if is_on_board(i):
- if check_spots_check:
- if !checkcheck(i):
- continue
+ if check_spots_check and checkcheck(i):
+ continue
final.append(i)
return final
diff --git a/pieces/Pawn.gd b/pieces/Pawn.gd
index 55892bc..7760913 100644
--- a/pieces/Pawn.gd
+++ b/pieces/Pawn.gd
@@ -13,9 +13,8 @@ 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:
- if !checkcheck(point):
- continue
+ if check_spots_check and checkcheck(point):
+ continue
if is_on_board(point):
moves.append(point)
return moves
diff --git a/pieces/Piece.gd b/pieces/Piece.gd
index 8e5dfbb..bc9068f 100644
--- a/pieces/Piece.gd
+++ b/pieces/Piece.gd
@@ -85,17 +85,11 @@ func traverse(arr = [Vector2.UP, Vector2.DOWN, Vector2.LEFT, Vector2.RIGHT]):
pos += i
if !is_on_board(pos):
break
-
if at_pos(pos) != null: # only one black
- # if check_spots_check:
- # if checkcheck(pos):
circle_array.append(pos)
break
- # break
- # break
- if check_spots_check:
- if !checkcheck(pos):
- continue
+ if check_spots_check and checkcheck(pos):
+ continue
circle_array.append(pos)
return circle_array
@@ -145,19 +139,17 @@ 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 not in check
+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
- print("moved " + shortname + " to " + str(pos))
- var retu = true # return true by default
+ var retu = false # return true by default
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
+ retu = true # return false, but fix the matrix first
# Globals.grid.print_matrix_pretty(mat) # print the matrix
Globals.grid.matrix = mat # revert changes on the matrix
return retu
- return true
+ return false
func is_on_board(vector: Vector2):