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; ...@@ -3,38 +3,77 @@ package model;
import java.util.Iterator; import java.util.Iterator;
public class CellGridIterator implements Iterator<Cell> { 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){ CellGridIterator(ArrayGrid grid){
PrvRow=ActRow=0;
PrvColmn=ActColmn=0;
this.grid=grid; this.grid=grid;
this.row=0;
this.column=0;
}
public
boolean hasNext ( ) {
return hasNextRow ()|| hasNextCol ();
} }
@Override public
public boolean hasNext() { Boolean hasNextCol (){
if((this.row==grid.getNumberOfRows()-1 && this.column==grid.getNumberOfColumns()-1)) {
return false;
return !(grid.getNumberOfColumns ()==ActColmn);
} }
return true;
public Boolean hasNextRow(){
return !(grid.getNumberOfRows ()-1==this.ActRow);
} }
@Override
public Cell next ( ) { public Cell next ( ) {
if (hasNext()) {
if (this.column >= 0 && this.column < grid.getNumberOfColumns()-1) { if ( hasNextCol ( ) ) {
this.column++; PrvColmn=ActColmn;
} else if (this.column == grid.getNumberOfColumns()-1 && this.row < grid.getNumberOfRows()-1) { ActColmn++;
this.column = 0; return grid.getCell (PrvRow,PrvColmn );
this.row++;
} }
if ( hasNextRow ( ) ) {
ActRow++;
ActColmn=1;
PrvColmn=0;
PrvRow=ActRow;
return grid.getCell ( PrvRow , PrvColmn );
return grid.getCell(row, column);
} }
return null; return null;
} }
} }
...@@ -8,6 +8,7 @@ import java.util.List; ...@@ -8,6 +8,7 @@ import java.util.List;
public class ComputerPlayer implements Player{ public class ComputerPlayer implements Player{
private String name; private String name;
private Cell startCell; private Cell startCell;
private PlayStrategy strategy;
ComputerPlayer(String name, Cell startCell){ ComputerPlayer(String name, Cell startCell){
this.name=name; this.name=name;
this.startCell=startCell; this.startCell=startCell;
...@@ -16,8 +17,7 @@ public class ComputerPlayer implements Player{ ...@@ -16,8 +17,7 @@ public class ComputerPlayer implements Player{
ComputerPlayer(String name, Cell startCell,PlayStrategy strategy){ ComputerPlayer(String name, Cell startCell,PlayStrategy strategy){
this.name=name; this.name=name;
this.startCell=startCell; this.startCell=startCell;
strategy.play(startCell); this.strategy=strategy;
} }
......
...@@ -56,13 +56,13 @@ public class FloodGame { ...@@ -56,13 +56,13 @@ public class FloodGame {
} }
public boolean hasWon(Player player) { public boolean hasWon(Player player) {
if (Flooder.coloredArea(player.getStartCell()) == totalFloodingArea-1) { if (Flooder.coloredArea(player.getStartCell()) == totalFloodingArea) {
return true; return true;
} }
return false; return false;
} }
public boolean hasEnded(){ 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