diff options
-rw-r--r-- | app.js | 48 | ||||
-rw-r--r-- | game.js | 21 | ||||
-rw-r--r-- | index.html | 128 |
3 files changed, 113 insertions, 84 deletions
@@ -1,17 +1,34 @@ - - let board = [ [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 3, 3, 3, 0, 0, 0], + [0, 0, 3, 2, 3, 0, 0, 0], + [0, 0, 3, 3, 3, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], ] -console.log(amelia_move(board, 7, 7)) +console.log(amelia_move(board, 3, 3)) + +function move(board, y, x) { + switch (board[y][x]) { + case 0: + break + case 1, -1: + return king_move(board, y, x) + case 2, -2: + return amelia_move(board, y, x) + case 3, -3: + return rook_move(board, y, x) + case 4, -4: + return bishop_move(board, y, x) + case 5, -5: + return knight_move(board, y, x) + case 6, -6: + return pawn_move(board, y, x) + } +} function pawn_move(board, y, x) { let moves = [] @@ -102,7 +119,8 @@ function rook_move(board, y, x) { for (let i = x + 1; i < board[1].length; i++) { if (board[y][i] != 0) { - if (color ^ board[y][i]) { + if (color ^ board[y][i] > 0) { + console.log(color ^ board[y][i]) moves.push([y, i]) break } @@ -113,7 +131,7 @@ function rook_move(board, y, x) { for (let i = x - 1; i >= 0; i--) { if (board[y][i] != 0) { - if (color ^ board[y][i]) { + if (color ^ board[y][i] > 0) { moves.push([y, i]) break } @@ -125,7 +143,7 @@ function rook_move(board, y, x) { for (let i = y + 1; i < board.length; i++) { if (board[i][x] != 0) { - if (color ^ board[i][x]) { + if (color ^ board[i][x] > 0) { moves.push([i, x]) break } @@ -136,7 +154,7 @@ function rook_move(board, y, x) { for (let i = y - 1; i >= 0; i--) { if (board[i][x] != 0) { - if (color ^ board[i][x]) { + if (color ^ board[i][x] > 0) { moves.push([i, x]) break } @@ -229,7 +247,8 @@ function amelia_move(board, y, x) { for (let i = x + 1; i < board[1].length; i++) { if (board[y][i] != 0) { - if (color ^ board[y][i]) { + if (color ^ board[y][i] > 0) { + console.log(color ^ board[y][i]) moves.push([y, i]) break } @@ -240,7 +259,7 @@ function amelia_move(board, y, x) { for (let i = x - 1; i >= 0; i--) { if (board[y][i] != 0) { - if (color ^ board[y][i]) { + if (color ^ board[y][i] > 0) { moves.push([y, i]) break } @@ -252,7 +271,7 @@ function amelia_move(board, y, x) { for (let i = y + 1; i < board.length; i++) { if (board[i][x] != 0) { - if (color ^ board[i][x]) { + if (color ^ board[i][x] > 0) { moves.push([i, x]) break } @@ -263,7 +282,7 @@ function amelia_move(board, y, x) { for (let i = y - 1; i >= 0; i--) { if (board[i][x] != 0) { - if (color ^ board[i][x]) { + if (color ^ board[i][x] > 0) { moves.push([i, x]) break } @@ -271,7 +290,6 @@ function amelia_move(board, y, x) { } moves.push([i, x]) } - let i = y + 1 let j = x + 1 @@ -1,4 +1,5 @@ const alphabet = 'abcdefgh' +let squares = document.getElementsByClassName("square") let board = [ [0, 0, 0, 0, 0, 0, 0, 0], @@ -11,16 +12,26 @@ let board = [ [0, 0, 0, 0, 0, 0, 0, 0], ] -for (let i = 0; i < 8; i ++) { - for (let j = 0; j < 8; j ++) { - let square = document.getElementById(`${alphabet.charAt(j)}${i+1}`) +for (let i = 0; i < 8; i++) { + for (let j = 0; j < 8; j++) { + let square = document.getElementById(`${alphabet.charAt(j)}${i + 1}`) + let piece = document.createElement("p") + switch (board[i][j]) { case 1: - square.append("p") + piece.classList.add("wp") + square.append(piece) + piece.append("p") break case -1: - square.append("p") + piece.classList.add("bp") + square.append(piece) + piece.append("p") break } } } + +for (let i = 0; i < squares.length; i++) { + +} @@ -10,84 +10,84 @@ <body> <div class="chess-board"> <div> - <div id="a8" class="1 white"></div> - <div id="a7" class="2 black"></div> - <div id="a6" class="3 white"></div> - <div id="a5" class="4 black"></div> - <div id="a4" class="5 white"></div> - <div id="a3" class="6 black"></div> - <div id="a2" class="7 white"></div> - <div id="a1" class="8 black"></div> + <div id="a8" class="white square"></div> + <div id="a7" class="black square"></div> + <div id="a6" class="white square"></div> + <div id="a5" class="black square"></div> + <div id="a4" class="white square"></div> + <div id="a3" class="black square"></div> + <div id="a2" class="white square"></div> + <div id="a1" class="black square"></div> </div> <div> - <div id="b8" class="2 black"></div> - <div id="b7" class="1 white"></div> - <div id="b6" class="4 black"></div> - <div id="b5" class="3 white"></div> - <div id="b4" class="6 black"></div> - <div id="b3" class="5 white"></div> - <div id="b2" class="8 black"></div> - <div id="b1" class="7 white"></div> + <div id="b8" class="black square"></div> + <div id="b7" class="white square"></div> + <div id="b6" class="black square"></div> + <div id="b5" class="white square"></div> + <div id="b4" class="black square"></div> + <div id="b3" class="white square"></div> + <div id="b2" class="black square"></div> + <div id="b1" class="white square"></div> </div> <div> - <div id="c8" class="1 white"></div> - <div id="c7" class="2 black"></div> - <div id="c6" class="3 white"></div> - <div id="c5" class="4 black"></div> - <div id="c4" class="5 white"></div> - <div id="c3" class="6 black"></div> - <div id="c2" class="7 white"></div> - <div id="c1" class="8 black"></div> + <div id="c8" class="white square"></div> + <div id="c7" class="black square"></div> + <div id="c6" class="white square"></div> + <div id="c5" class="black square"></div> + <div id="c4" class="white square"></div> + <div id="c3" class="black square"></div> + <div id="c2" class="white square"></div> + <div id="c1" class="black square"></div> </div> <div> - <div id="d8" class="2 black"></div> - <div id="d7" class="1 white"></div> - <div id="d6" class="4 black"></div> - <div id="d5" class="3 white"></div> - <div id="d4" class="6 black"></div> - <div id="d3" class="5 white"></div> - <div id="d2" class="8 black"></div> - <div id="d1" class="7 white"></div> + <div id="d8" class="black square"></div> + <div id="d7" class="white square"></div> + <div id="d6" class="black square"></div> + <div id="d5" class="white square"></div> + <div id="d4" class="black square"></div> + <div id="d3" class="white square"></div> + <div id="d2" class="black square"></div> + <div id="d1" class="white square"></div> </div> <div> - <div id="e8" class="1 white"></div> - <div id="e7" class="2 black"></div> - <div id="e6" class="3 white"></div> - <div id="e5" class="4 black"></div> - <div id="e4" class="5 white"></div> - <div id="e3" class="6 black"></div> - <div id="e2" class="7 white"></div> - <div id="e1" class="8 black"></div> + <div id="e8" class="white square"></div> + <div id="e7" class="black square"></div> + <div id="e6" class="white square"></div> + <div id="e5" class="black square"></div> + <div id="e4" class="white square"></div> + <div id="e3" class="black square"></div> + <div id="e2" class="white square"></div> + <div id="e1" class="black square"></div> </div> <div> - <div id="f8" class="2 black"></div> - <div id="f7" class="1 white"></div> - <div id="f6" class="4 black"></div> - <div id="f5" class="3 white"></div> - <div id="f4" class="6 black"></div> - <div id="f3" class="5 white"></div> - <div id="f2" class="8 black"></div> - <div id="f1" class="7 white"></div> + <div id="f8" class="black square"></div> + <div id="f7" class="white square"></div> + <div id="f6" class="black square"></div> + <div id="f5" class="white square"></div> + <div id="f4" class="black square"></div> + <div id="f3" class="white square"></div> + <div id="f2" class="black square"></div> + <div id="f1" class="white square"></div> </div> <div> - <div id="g8" class="1 white"></div> - <div id="g7" class="2 black"></div> - <div id="g6" class="3 white"></div> - <div id="g5" class="4 black"></div> - <div id="g4" class="5 white"></div> - <div id="g3" class="6 black"></div> - <div id="g2" class="7 white"></div> - <div id="g1" class="8 black"></div> + <div id="g8" class="white square"></div> + <div id="g7" class="black square"></div> + <div id="g6" class="white square"></div> + <div id="g5" class="black square"></div> + <div id="g4" class="white square"></div> + <div id="g3" class="black square"></div> + <div id="g2" class="white square"></div> + <div id="g1" class="black square"></div> </div> <div> - <div id="h8" class="2 black"></div> - <div id="h7" class="1 white"></div> - <div id="h6" class="4 black"></div> - <div id="h5" class="3 white"></div> - <div id="h4" class="6 black"></div> - <div id="h3" class="5 white"></div> - <div id="h2" class="8 black"></div> - <div id="h1" class="7 white"></div> + <div id="h8" class="black square"></div> + <div id="h7" class="white square"></div> + <div id="h6" class="black square"></div> + <div id="h5" class="white square"></div> + <div id="h4" class="black square"></div> + <div id="h3" class="white square"></div> + <div id="h2" class="black square"></div> + <div id="h1" class="white square"></div> </div> </div> <script src="./game.js"></script> |