Skip to content
Snippets Groups Projects
Commit 26c5ffb9 authored by EL GAOUAL Zaid's avatar EL GAOUAL Zaid
Browse files

Strategy walk

parent ffa012ef
No related branches found
No related tags found
No related merge requests found
......@@ -3,38 +3,77 @@ package model;
import java.util.Iterator;
public class CellGridIterator implements Iterator<Cell> {
public ArrayGrid grid;
public int row;
public int column;
private ArrayGrid grid;
private int PrvColmn;
private int PrvRow;
private int ActColmn;
private int ActRow;
CellGridIterator(ArrayGrid grid){
PrvRow=ActRow=0;
PrvColmn=ActColmn=0;
this.grid=grid;
this.row=0;
this.column=0;
}
public
boolean hasNext ( ) {
return hasNextRow ()|| hasNextCol ();
}
@Override
public boolean hasNext() {
if((this.row==grid.getNumberOfRows()-1 && this.column==grid.getNumberOfColumns()-1)) {
return false;
public
Boolean hasNextCol (){
return !(grid.getNumberOfColumns ()==ActColmn);
}
return true;
public Boolean hasNextRow(){
return !(grid.getNumberOfRows ()-1==this.ActRow);
}
@Override
public Cell next ( ) {
if (hasNext()) {
if (this.column >= 0 && this.column < grid.getNumberOfColumns()-1) {
this.column++;
} else if (this.column == grid.getNumberOfColumns()-1 && this.row < grid.getNumberOfRows()-1) {
this.column = 0;
this.row++;
if ( hasNextCol ( ) ) {
PrvColmn=ActColmn;
ActColmn++;
return grid.getCell (PrvRow,PrvColmn );
}
if ( hasNextRow ( ) ) {
ActRow++;
ActColmn=1;
PrvColmn=0;
PrvRow=ActRow;
return grid.getCell ( PrvRow , PrvColmn );
return grid.getCell(row, column);
}
return null;
}
}
......@@ -8,6 +8,7 @@ import java.util.List;
public class ComputerPlayer implements Player{
private String name;
private Cell startCell;
private PlayStrategy strategy;
ComputerPlayer(String name, Cell startCell){
this.name=name;
this.startCell=startCell;
......@@ -16,8 +17,7 @@ public class ComputerPlayer implements Player{
ComputerPlayer(String name, Cell startCell,PlayStrategy strategy){
this.name=name;
this.startCell=startCell;
strategy.play(startCell);
this.strategy=strategy;
}
......
......@@ -56,13 +56,13 @@ public class FloodGame {
}
public boolean hasWon(Player player) {
if (Flooder.coloredArea(player.getStartCell()) == totalFloodingArea-1) {
if (Flooder.coloredArea(player.getStartCell()) == totalFloodingArea) {
return true;
}
return false;
}
public boolean hasEnded(){
return (hasWon(player)||getPlayerScore(player)==1);
return (hasWon(player)||getPlayerScore(player)==0);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment