-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
57 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
const $ = (id) => document.getElementById(id); | ||
const $q = (q) => document.querySelector(q); | ||
const $qa = (qa) => document.querySelectorAll(qa); | ||
function $(id) { | ||
return document.getElementById(id); | ||
} | ||
|
||
function $q(q) { | ||
return document.querySelector(q); | ||
} | ||
|
||
function $qa(q) { | ||
return document.getElementById(q); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,4 @@ const DOM = { | |
}, | ||
}; | ||
|
||
|
||
export default DOM; | ||
export default DOM; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import { Players } from "./constants.js"; | ||
import Game from './game.js'; | ||
|
||
const AI = { | ||
move() { | ||
const availableMoves = []; | ||
function AIMove() { | ||
const availableMoves = []; | ||
|
||
// Collect all available moves (empty cells) | ||
for (let x = 0; x < 3; x++) { | ||
for (let y = 0; y < 3; y++) { | ||
if (Game.cells[x][y] === Players.EMPTY) { | ||
availableMoves.push({ x, y }); | ||
} | ||
} | ||
} | ||
// Collect all available moves (empty cells) | ||
Game.cells.forEach(col => { | ||
col.forEach(cell => { | ||
if (Game.cells[x][y] === Players.EMPTY) { | ||
availableMoves.push({ x, y }); | ||
} | ||
}); | ||
}); | ||
|
||
// Pick a random move from available moves | ||
const randomMove = availableMoves[Math.floor(Math.random() * availableMoves.length)]; | ||
if (randomMove) { | ||
Game.captureCell(randomMove.x, randomMove.y); | ||
} | ||
} | ||
}; | ||
if (availableMoves.length == 0) { | ||
return; | ||
} | ||
|
||
export default AI; | ||
// Pick a random move from available moves | ||
const randomMove = availableMoves[Math.floor(Math.random() * availableMoves.length)]; | ||
Game.captureCell(randomMove.x, randomMove.y); | ||
} | ||
|
||
export default AIMove; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,4 @@ DOM.cells.forEach((cell, index) => { | |
const y = index % 3; | ||
Game.captureCell(x, y); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,6 @@ | |
|
||
|
||
.things { | ||
padding-top: .25rem; | ||
background: var(--bg-2); | ||
} | ||
|
||
|