From a5d8512b34b6141622d66797756721de356c4bea Mon Sep 17 00:00:00 2001 From: Cyprien111 <105004796+Cyprien111@users.noreply.github.com> Date: Mon, 31 Mar 2025 10:10:27 +0200 Subject: [PATCH] AI and player play correctly --- src/GomokuAI.java | 22 ++++++++++++++-------- src/Human.java | 5 +++-- src/Player.java | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/GomokuAI.java b/src/GomokuAI.java index 850cfb0..35bc93f 100644 --- a/src/GomokuAI.java +++ b/src/GomokuAI.java @@ -1,3 +1,4 @@ +import java.util.List; import java.util.Random; public class GomokuAI{ @@ -17,20 +18,25 @@ public class GomokuAI{ * @param Board The actual Gomoku board. * @return The coordinate of the move played. */ - public Coordinate chooseMove(GomokuBoard board){ - + public GomokuCell chooseMove(GomokuBoard board){ + List playableCell = board.getPlayableCells(); + GomokuCell playCell; int x=0,y=0; - if(difficulty == 0) - { - int rand = random.nextInt(board.getPlayableCells().size()); - - } + switch (difficulty) { + case 0: + playCell = playableCell.get(random.nextInt(playableCell.size())); + break; + case 1: + System.out.println("L'IA réflechit..."); + default: + throw new AssertionError(); + } System.out.println("L'IA à choisi : "+ x+", "+ y); - return new Coordinate(x,y); + return playCell; } } \ No newline at end of file diff --git a/src/Human.java b/src/Human.java index 2e63a3c..1b2e0b2 100644 --- a/src/Human.java +++ b/src/Human.java @@ -1,5 +1,6 @@ import java.io.Console; +import javax.swing.plaf.basic.BasicBorders; public class Human extends Player{ @@ -13,7 +14,7 @@ public class Human extends Player{ * @param Board The actual Gomoku board. * @return The coordinate of the move played. */ - public Coordinate chooseMove(GomokuBoard board){ + public GomokuCell chooseMove(GomokuBoard board){ Console cons = System.console(); @@ -60,6 +61,6 @@ public class Human extends Player{ System.out.println("Vous avez saisi : "+ x+", "+ y); - return new Coordinate(x,y); + return board.get(x,y); } } \ No newline at end of file diff --git a/src/Player.java b/src/Player.java index 73138d0..18e65ee 100644 --- a/src/Player.java +++ b/src/Player.java @@ -38,5 +38,5 @@ abstract class Player{ * @param Board The actual Gomoku board. * @return The coordinate of the move played. */ - public abstract Coordinate chooseMove(GomokuBoard board); + public abstract GomokuCell chooseMove(GomokuBoard board); } \ No newline at end of file