summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/board.js16
-rw-r--r--public/move.js5
2 files changed, 8 insertions, 13 deletions
diff --git a/public/board.js b/public/board.js
index 94c72ac..0c07d80 100644
--- a/public/board.js
+++ b/public/board.js
@@ -13,17 +13,11 @@ for (let i = 0; i < squares.length; i++) {
function handle_highlight(id) {
return function() {
-
let moves = move(board, id.charCodeAt(0) - 48, id.charCodeAt(1) - 48, to_move)
- for (let i = 0; i < previously_highlighted_squares.length; i++) {
- //if (previously_highlighted_squares[i] == piece_square) {
- // continue
- //}
-
- let prev = document.getElementById(previously_highlighted_squares[i])
- prev.classList.remove('highlight')
- prev.onclick = null
+ for (let i = 0; i < squares.length; i++) {
+ squares[i].classList.remove('highlight')
+ squares[i].onclick = handle_highlight(squares[i].id)
}
for (let i = 0; i < moves.length; i++) {
@@ -39,9 +33,9 @@ function handle_highlight(id) {
function handle_move(from_id, to_id) {
return function() {
+
let table = { 1: 'K', 2: 'Q', 3: 'R', 4: 'B', 5: 'N', 6: 'p' }
- console.log(from_id.charCodeAt(0) - 48, from_id.charCodeAt(1) - 48, to_id.charCodeAt(0) - 48, to_id.charCodeAt(1) - 48)
make_move(board, from_id.charCodeAt(0) - 48, from_id.charCodeAt(1) - 48, to_id.charCodeAt(0) - 48, to_id.charCodeAt(1) - 48)
let from_element = document.getElementById(from_id)
@@ -58,7 +52,7 @@ function handle_move(from_id, to_id) {
for (let i = 0; i < previously_highlighted_squares.length; i++) {
let prev = document.getElementById(previously_highlighted_squares[i])
prev.classList.remove('highlight')
- prev.onclick = null
+ prev.onclick = handle_highlight
}
let piece = document.createElement('p')
diff --git a/public/move.js b/public/move.js
index ee527c6..5dc49af 100644
--- a/public/move.js
+++ b/public/move.js
@@ -12,7 +12,7 @@ let board = [
let to_move = true //white to move
//console.log(board[7][1])
-//console.log(move(board, 7, 1, to_move))
+//console.log(move(board, 3, 1, to_move))
function move(board, y, x, to_move) {
if (to_move ^ board[y][x] > 0) {
@@ -69,9 +69,10 @@ function pawn_move(board, y, x) {
if (board[y + 2][x] == 0) {
moves.push([y + 2, x])
}
- } else if (color && y != 7 && board[y + 1][x] == 0) {
+ } else if (!color && y != 7 && board[y + 1][x] == 0) {
moves.push([y + 1, x])
}
+
return moves
}
}