Skip to content
Snippets Groups Projects
Commit fca8faee authored by NGUYEN Thi hang's avatar NGUYEN Thi hang
Browse files

THN 22H12 18/11/2022

parent 22c0bdc1
No related branches found
No related tags found
No related merge requests found
...@@ -160,7 +160,7 @@ public class GameController { ...@@ -160,7 +160,7 @@ public class GameController {
// TODO // TODO
// Player player = ... instantiate a ComputerPlayer named "cyclic" that follows the cyclic strategy // Player player = ... instantiate a ComputerPlayer named "cyclic" that follows the cyclic strategy
// game.setPlayer(player); // game.setPlayer(player);
Player player= new ComputerPlayer("Robin", getGridStartCell(), new CyclicStrategy(availableColors)); Player player= new ComputerPlayer("cyclic", getGridStartCell(), new CyclicStrategy(availableColors));
game.setPlayer(player); game.setPlayer(player);
} }
......
...@@ -23,18 +23,18 @@ public class ArrayGrid implements Grid{ ...@@ -23,18 +23,18 @@ public class ArrayGrid implements Grid{
} }
} }
int mx[] = {0, 0, -1, 1}; int x[] = {0, 0, -1, 1};
int my[] = {-1, 1, 0, 0}; int y[] = {-1, 1, 0, 0};
for (int rowIndex= 0; rowIndex < numberOfRows ; rowIndex++) { for (int rowIndex= 0; rowIndex < numberOfRows ; rowIndex++) {
for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) { for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
// Adding neighbor list // Adding neighbor list
List<Cell> neighbors = new ArrayList<Cell>(); List<Cell> neighbors = new ArrayList<Cell>();
for(int k = 0; k < 4; k++){ for(int k = 0; k < 4; k++){
int c_x = rowIndex + mx[k]; int cellX = rowIndex + x[k];
int c_y = columnIndex + my[k]; int cellY = columnIndex + y[k];
if (c_x >= 0 && c_x < numberOfRows & c_y >= 0 && c_y < numberOfColumns) { if (cellX >= 0 && cellX < numberOfRows & cellY >= 0 && cellY < numberOfColumns) {
neighbors.add(this.cells[c_x][c_y]); neighbors.add(this.cells[cellX][cellY]);
} }
} }
......
...@@ -3,9 +3,7 @@ package model; ...@@ -3,9 +3,7 @@ package model;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import util.RandomUtil; import util.RandomUtil;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Random;
public class RandomWalk implements PlayStrategy{ public class RandomWalk implements PlayStrategy{
private List<Color> colors; private List<Color> colors;
...@@ -19,11 +17,20 @@ public class RandomWalk implements PlayStrategy{ ...@@ -19,11 +17,20 @@ public class RandomWalk implements PlayStrategy{
} }
@Override @Override
public Color play(Cell startCell) { public Color play(Cell startCell) {
List<Color>colorNeighbor=new ArrayList<Color>(); // choisir une des couleurs des voisins qui est différent que startCell (où on est)
for(Cell cell:startCell.getNeighbours()) Set<Color> colorNeighbor=new HashSet<Color>();
colorNeighbor.add(cell.getColor());
if (colorNeighbor.contains(startCell.getColor())){ ColoredCellIterator colored_iterator = new ColoredCellIterator(startCell);
colorNeighbor.remove(startCell.getColor());}
return RandomUtil.randomElement(colorNeighbor,this.randomColor); while(colored_iterator.hasNext()){
Cell current_cell = colored_iterator.next();
List<Cell> current_neighbors = current_cell.getNeighbours();
for(Cell c : current_neighbors){
if(c.getColor() != startCell.getColor())
colorNeighbor.add(c.getColor());
}
}
return RandomUtil.randomElement(new ArrayList<Color>(colorNeighbor),this.randomColor);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment