diff --git a/back-end/ai/board.go b/back-end/ai/board.go index ceca2fa..55789a2 100644 --- a/back-end/ai/board.go +++ b/back-end/ai/board.go @@ -10,7 +10,6 @@ type Board struct { saturation uint8 // How much of the board is filled up } -// ? FIX SEGMENT COUNT BUG func (board *Board) agentPerformanceEvaluation(piece uint8) int { var segmentInstances [6]int performance := 0 diff --git a/back-end/ai/game.go b/back-end/ai/game.go index 90ccbcf..5a5e4b3 100644 --- a/back-end/ai/game.go +++ b/back-end/ai/game.go @@ -1,16 +1,5 @@ package ai -/* - * UI - * board - * static eval - * minimax + pruning - * Utility of move - * Concurrency - ? Caching - ? Move Ordering -*/ - type Response struct { AIMove uint8 `json:"AIMove"` IsGameOver bool `json:"isGameOver"` diff --git a/back-end/server.go b/back-end/server.go index f45dbf6..13c2493 100644 --- a/back-end/server.go +++ b/back-end/server.go @@ -21,7 +21,9 @@ func main() { r := gin.Default() r.Use(cors.Default()) // Allow all origins - r.POST("/", func(c *gin.Context) { + r.Static("/", "./dist/") + + r.POST("/ai", func(c *gin.Context) { var grid Request if err := c.BindJSON(&grid); err != nil { diff --git a/front-end/.env b/front-end/.env deleted file mode 100644 index 9022af8..0000000 --- a/front-end/.env +++ /dev/null @@ -1 +0,0 @@ -AI_SERVER=http://localhost:5000 diff --git a/front-end/src/components/Board.tsx b/front-end/src/components/Board.tsx index e01ddcf..959b4fb 100644 --- a/front-end/src/components/Board.tsx +++ b/front-end/src/components/Board.tsx @@ -1,13 +1,13 @@ -import { Box, Flex, SimpleGrid } from "@chakra-ui/react"; -import { useEffect, useRef, useState } from "react"; -import Stone, { stoneSize } from "./Stone"; -import LineGrid from "./LineGrid"; -import BoardLock from "./BoardLock"; -import UndoButton from "./UndoButton"; -import ClearButton from "./ClearButton"; +import { Box, Flex, SimpleGrid } from "@chakra-ui/react" +import { useEffect, useRef, useState } from "react" +import Stone, { stoneSize } from "./Stone" +import LineGrid from "./LineGrid" +import BoardLock from "./BoardLock" +import UndoButton from "./UndoButton" +import ClearButton from "./ClearButton" -export const boardSize = `${(10 + (10 - 1) / 2) * stoneSize}rem`; -const stoneSpacing = `${stoneSize / 2}rem`; +export const boardSize = `${(10 + (10 - 1) / 2) * stoneSize}rem` +const stoneSpacing = `${stoneSize / 2}rem` export enum StoneIndicator { EMPTY, WHITE, @@ -16,28 +16,21 @@ export enum StoneIndicator { const Board = () => { const [board, setBoard] = useState(() => { - const filler = new Array(10 * 10); + const filler = new Array(10 * 10) for (let i = 0; i < 10 * 10; ++i) { - filler[i] = StoneIndicator.EMPTY; + filler[i] = StoneIndicator.EMPTY } - return filler; - }); - const [isFetching, setIsFetching] = useState(false); - const [isGameOver, setIsGameOver] = useState(false); - const history = useRef([]); + return filler + }) + const [isFetching, setIsFetching] = useState(false) + const [isGameOver, setIsGameOver] = useState(false) + const history = useRef([]) useEffect(() => { - /* - * * Push move to history - * * Update move in board - * * Update isFetching state - * * Handle Game Over - * * Response JSON : {"AIMove": 0,"isGameOver":false} - */ if (isFetching) { const fetchAIMove = async () => { - const response = await fetch("http://localhost:5000/", { + const response = await fetch("http://localhost:5000/ai", { method: "POST", headers: { "Content-type": "application/json", @@ -45,25 +38,25 @@ const Board = () => { body: JSON.stringify({ grid: board, }), - }); + }) - const { AIMove, isGameOver } = await response.json(); + const { AIMove, isGameOver } = await response.json() - history.current.push(AIMove); + history.current.push(AIMove) - setBoard(prevBoard => { - const mutatedBoard = [...prevBoard]; - mutatedBoard[AIMove] = StoneIndicator.WHITE; - return mutatedBoard; - }); + setBoard((prevBoard) => { + const mutatedBoard = [...prevBoard] + mutatedBoard[AIMove] = StoneIndicator.WHITE + return mutatedBoard + }) - setIsFetching(false); - setIsGameOver(isGameOver); - }; + setIsFetching(false) + setIsGameOver(isGameOver) + } - fetchAIMove(); + fetchAIMove() } - }, [isFetching]); + }, [isFetching]) return ( @@ -82,11 +75,18 @@ const Board = () => { /> - + {board.map((stoneIndicator, i) => ( { {isGameOver && } - ); -}; + ) +} -export default Board; +export default Board