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

THN 22h34 18/11/2022

parent fca8faee
No related branches found
No related tags found
No related merge requests found
......@@ -3,9 +3,9 @@ package model;
import java.util.Iterator;
public class CellGridIterator implements Iterator<Cell> {
ArrayGrid grid;
int indixRow;
int indixColum;
public ArrayGrid grid;
public int indixRow;
public int indixColum;
public CellGridIterator(ArrayGrid grid) {
this.grid = grid;
......
......@@ -44,10 +44,10 @@ public class ComputerPlayer implements Player{
public Color play(){
return this.strategi.play(this.getStartCell());// Color.RED;
}
// public Color setStrategy(PlayStrategy strategy){
// this.strategi=strategy;
// return this.play();
// }
public Color setStrategy(PlayStrategy strategy){
this.strategi=strategy;
return this.play();
}
public void setStartCell(Cell start){
this.cellStart=start;
}
......
......@@ -17,11 +17,8 @@ public class DistinctColorGenerator implements ColorGenerator {
List<Cell> neighbors = cell.getNeighbours();
//System.out.println(neighbors.size());
List<Color> neighbor_colors = new ArrayList<Color>();
for (Cell c : neighbors) {
neighbor_colors.add(c.getColor());
}
......@@ -30,15 +27,6 @@ public class DistinctColorGenerator implements ColorGenerator {
if (neighbor_colors.contains(colors.get(i)) == false){
return colors.get(i);
}
// int j = 0;
// for (; j < neighbor_colors.size(); j++) {
// if (colors.get(i).equals(neighbor_colors.get(j)) == true)
// break;//if (!(neighbor_colors.contains(colors.get(i)))){
// }
//
// if(j == neighbor_colors.size()){
// return colors.get(i);
// }
}
return defaultColor;
......
......@@ -62,7 +62,7 @@ public class FloodGame {
public boolean hasEnded(){
// TODO
return (this.getTurn()>=25 || hasWon(player));
return (this.getTurn()>=100 || hasWon(player));
}
}
......@@ -9,9 +9,9 @@ import java.util.List;
public class GrayCell extends AbstractCell{
Cell[][] cells;
int nberOfRows;
int nberOfColums;
public Cell[][] cells;
public int nberOfRows;
public int nberOfColums;
List<Cell> neighbours;
public GrayCell(Cell[][] cells, int rows, int colums){
......
......@@ -3,7 +3,7 @@ package model;
import javafx.scene.paint.Color;
public class UniformColorGenerator implements ColorGenerator{
Color color;
public Color color;
public UniformColorGenerator(Color color){
this.color=color;
}
......
......@@ -3,8 +3,8 @@ package model;
import javafx.scene.paint.Color;
public class UniformExceptOneGenerator implements ColorGenerator{
Color uniformColor;
Color exceptionColor;
public Color uniformColor;
public Color exceptionColor;
public UniformExceptOneGenerator(Color uniformColor, Color exceptionColor){
this.uniformColor=uniformColor;
this.exceptionColor=exceptionColor;
......
package model;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import javafx.scene.paint.Color;
class FlooderTest {
/*
* +---+---+---+
* | R | B | R |
* +---+---+---|
* | R | R | B |
* |---+---+---+
* | B | B | R |
* +---+---+---+
*/
private static ArrayGrid gridThreeThree = new ArrayGrid(3,3);
@BeforeAll
private static void initializeColorsGrid33(){
gridThreeThree.getCell(0,0).setColor(Color.RED);
gridThreeThree.getCell(0,1).setColor(Color.BLACK);
gridThreeThree.getCell(0,2).setColor(Color.RED);
gridThreeThree.getCell(1,0).setColor(Color.RED);
gridThreeThree.getCell(1,1).setColor(Color.RED);
gridThreeThree.getCell(1,2).setColor(Color.BLACK);
gridThreeThree.getCell(2,0).setColor(Color.BLACK);
gridThreeThree.getCell(2,1).setColor(Color.BLACK);
gridThreeThree.getCell(2,2).setColor(Color.RED);
}
@Test
void testcoloredArea() {
int area1 = Flooder.coloredArea(gridThreeThree.getCell(0,0));
int area2 = Flooder.coloredArea(gridThreeThree.getCell(2,0));
assertEquals(area1, 7);
assertEquals(area2, 7);
}
@Test
void testFlood() {
Flooder.flood(gridThreeThree.getCell(0, 0), Color.BLACK);
int area = Flooder.coloredArea(gridThreeThree.getCell(0,0));
assertThat(area == 3);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment