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 {
// TODO
// Player player = ... instantiate a ComputerPlayer named "cyclic" that follows the cyclic strategy
// game.setPlayer(player);
Player player= new ComputerPlayer("Robin", getGridStartCell(), new CyclicStrategy(availableColors));
Player player= new ComputerPlayer("cyclic", getGridStartCell(), new CyclicStrategy(availableColors));
game.setPlayer(player);
}
......
......@@ -23,18 +23,18 @@ public class ArrayGrid implements Grid{
}
}
int mx[] = {0, 0, -1, 1};
int my[] = {-1, 1, 0, 0};
int x[] = {0, 0, -1, 1};
int y[] = {-1, 1, 0, 0};
for (int rowIndex= 0; rowIndex < numberOfRows ; rowIndex++) {
for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
// Adding neighbor list
List<Cell> neighbors = new ArrayList<Cell>();
for(int k = 0; k < 4; k++){
int c_x = rowIndex + mx[k];
int c_y = columnIndex + my[k];
if (c_x >= 0 && c_x < numberOfRows & c_y >= 0 && c_y < numberOfColumns) {
neighbors.add(this.cells[c_x][c_y]);
int cellX = rowIndex + x[k];
int cellY = columnIndex + y[k];
if (cellX >= 0 && cellX < numberOfRows & cellY >= 0 && cellY < numberOfColumns) {
neighbors.add(this.cells[cellX][cellY]);
}
}
......
......@@ -3,9 +3,7 @@ package model;
import javafx.scene.paint.Color;
import util.RandomUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.*;
public class RandomWalk implements PlayStrategy{
private List<Color> colors;
......@@ -19,11 +17,20 @@ public class RandomWalk implements PlayStrategy{
}
@Override
public Color play(Cell startCell) {
List<Color>colorNeighbor=new ArrayList<Color>();
for(Cell cell:startCell.getNeighbours())
colorNeighbor.add(cell.getColor());
if (colorNeighbor.contains(startCell.getColor())){
colorNeighbor.remove(startCell.getColor());}
return RandomUtil.randomElement(colorNeighbor,this.randomColor);
// choisir une des couleurs des voisins qui est différent que startCell (où on est)
Set<Color> colorNeighbor=new HashSet<Color>();
ColoredCellIterator colored_iterator = new ColoredCellIterator(startCell);
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