online multiplayer chess game (note server currently down)
-rw-r--r--Grid.gd2
-rw-r--r--pieces/Queen.gd30
2 files changed, 31 insertions, 1 deletions
diff --git a/Grid.gd b/Grid.gd
index fed1d80..42731a6 100644
--- a/Grid.gd
+++ b/Grid.gd
@@ -41,6 +41,8 @@ func check_in_check(): # check if in_check
for j in range(0, 8): # for each column
var spot = matrix[i][j] # get the square
if spot and spot.white != Globals.turn: # enemie
+ if spot.shortname == "qW":
+ print("going through white queen")
if matrix[i][j].can_check_king(Globals.white_king if Globals.turn else Globals.black_king): # if it can take the king
Globals.in_check = true # set in_check
Globals.checking_piece = matrix[i][j] # set checking_piece
diff --git a/pieces/Queen.gd b/pieces/Queen.gd
index 8fdb900..d500356 100644
--- a/pieces/Queen.gd
+++ b/pieces/Queen.gd
@@ -3,7 +3,35 @@ class_name Queen
func get_moves():
- return .traverse(.all_dirs())
+ return traverse(all_dirs())
+
+
+func get_attacks(): # @Override
+ var moves = get_moves() # assumes the attacks are same as moves
+ var final = []
+ print("getting attacks from moves, moves: " + str(moves))
+ for i in moves:
+ if at_pos(i) != null and at_pos(i).white != white:
+ final.append(i)
+ print("final: " + str(final))
+ return final
+
+
+func can_check_king(king):
+ print("queen looking for king")
+ check_spots_check = false
+ print("starting the loop")
+ var attacks = get_attacks()
+ print("get attacks is: " + str(attacks))
+ # assert(get_attacks())
+ for attack in attacks:
+ if at_pos(attack) == king:
+ print("queen found king")
+ check_spots_check = true
+ return true
+ print(str(attack) + " was not king")
+ check_spots_check = true
+ return false
func _ready():