Skip to content

Commit

Permalink
fix: fix board array
Browse files Browse the repository at this point in the history
  • Loading branch information
Slijeff committed May 30, 2022
1 parent 284c90c commit b6ddddb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# game-ai
A survey of game AIs, including classic algorithms such as Minimax and MCTS.
A survey of game AIs, including classic algorithms such as Minimax and MCTS.

![Screenshot of UI](screenshot1.png?raw=true)

## Goals
- [X] Implement Minimax agent
- [ ] Implement MCTS agent
- [X] Implement Gomoku class
- [X] Implement Tic-tac-toe class
- [ ] Implement front-end
- [X] Implement front-end
- [X] Implement flask backend
13 changes: 11 additions & 2 deletions frontend/src/components/Board.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const Board = ({ clearSignal, serverAddr }) => {
calBoard.current = matrix;
setNotEmpty.toggle();
}

const loadingToast = toast({
title: "Calculating...",
description: "This might take a while",
Expand All @@ -44,14 +43,24 @@ export const Board = ({ clearSignal, serverAddr }) => {
toast.close(loadingToast);

const json = await data.json();
console.log(json["finished"]);
if (json["finished"] === true) {
toast({
title: "Game Complete",
duration: null,
position: "top",
isClosable: true,
status: "warning"
});
}
const resBoard = json["board"];
for (let i = 0; i < board.getSize(); i++) {
for (let j = 0; j < board.getSize(); j++) {
if (
resBoard[i][j] === "x" &&
calBoard.current[j + i * board.getSize()] !== "x"
) {
stones.current.push(i + j * board.getSize());
stones.current.push(j + i * board.getSize());
board.addObject(new FieldBoardObject("W", j, i));
}
}
Expand Down
Binary file added screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def aiplay():
heap = []
for move, row, col in all_moves:
print("Calculating move for row: {}, col: {}".format(row, col))
score = agent.get_score(move, data["depth"])
score = agent.get_score(move, int(data["depth"]))
heapq.heappush(heap, (-score, (row, col)))
airow, aicol = heapq.heappop(heap)[1]
gomoku.set_marker(airow, aicol, gomoku.player_marker)
Expand Down Expand Up @@ -59,4 +59,4 @@ def getBoard():


if __name__ == "__main__":
app.run(host="127.0.0.1", port=5000, debug=False)
app.run(host="127.0.0.1", port=5000, debug=True)

0 comments on commit b6ddddb

Please sign in to comment.