From 60afcfac8f6a619a6de56e34849b7c0f4bf59c61 Mon Sep 17 00:00:00 2001 From: Cyprien111 <105004796+Cyprien111@users.noreply.github.com> Date: Mon, 7 Apr 2025 09:01:15 +0200 Subject: [PATCH] play funcytion --- src/GomokuAI.java | 2 +- src/GomokuGame.java | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/GomokuAI.java b/src/GomokuAI.java index f7d9ceb..13c3f55 100644 --- a/src/GomokuAI.java +++ b/src/GomokuAI.java @@ -9,7 +9,7 @@ public class GomokuAI extends Player{ //------------------Constructors-------------------------- /** - * The constructor of the Human. + * The constructor of the GomokuAI. * @param name The name of the player. * @param color The color of the player. */ diff --git a/src/GomokuGame.java b/src/GomokuGame.java index 10eee43..1d47eea 100644 --- a/src/GomokuGame.java +++ b/src/GomokuGame.java @@ -1,8 +1,8 @@ -import java.nio.file.Path; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; public class GomokuGame { @@ -44,6 +44,29 @@ public class GomokuGame { } + /** + * Place the token on the cell where the player play. + * @param turn the turn of the player. + */ + public void play(int turn) { + + GomokuCell cellToPlay = null; + switch (turn) { + case 1: + cellToPlay = player1.chooseMove(board); + break; + case 2: + cellToPlay = player2.chooseMove(board); + break; + default: + throw new IllegalArgumentException("Invalid turn: " + turn); + } + + cellToPlay.setState(colorP1); + } + + + public boolean save(Path filename) { // save the game state to the file // 1. Open the file