package pylos.ai;

import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;

import pylos.model.Ball;
import pylos.model.Model;
import pylos.model.Position;

@SuppressWarnings("rawtypes")
public class GameState implements Enumeration {
	
	List<Ball> balls;
	List<Ball> onBoard;
	List<GameState> possibleMoves;
	List<Move> moves;
	private int score;
	
	public GameState(List<Ball> balls) {
		moves = new LinkedList<Move>();
		for (Ball ball : balls) {
			if(ball.onBoard)
				onBoard.add(ball);
			else
				this.balls.add(ball);
		}
	}
	
	public GameState(List<Ball> onBoard, List<Ball> onSide) {
		balls = onSide;
		this.onBoard = onBoard;
	}
	
	public int getScore() {
		return score;
	}
	
	public void add(int a) {
		score += a;
	}
	
	public void generatePosibleMove() {
		for (Ball ball : onBoard) {
			if(ball.isMountableByCurrentPlayer()) {
				for (Position pos : Model.getPositionsToMount(ball)) {
					Move move = new Move(ball, pos);
					if(move.anyLineOrSquareForMove())
						addRemovableStep(move);
					moves.add(move);
				}
			}
		}
		for (Position pos : Model.getPositionBalls()) {
			moves.add(new Move(balls.get(0), pos));
		}
	}

	private void addRemovableStep(Move move) {
		for (Ball ball : onBoard) {
			if(ball.isRemovableByCurrentPlayer())
				move.removables.add(new Move(ball, "remove"));
			for (Ball ball2 : onBoard) {
				if(ball2 != ball && ball2.isRemovableByCurrentPlayer() && ball.isRemovableByCurrentPlayer())
					move.removables.add(new Move(ball, ball2));
			}
		}
		
	}

	@Override
	public boolean hasMoreElements() {
		return !moves.isEmpty();
	}

	@Override
	public GameState nextElement() {
		List<Ball> oS = balls;
		List<Ball> oB = onBoard;
		Move move = moves.get(0);
		if(move.removeStep) {
			
		}
		moves.remove(0);
		move.ball.position = move.position;
		if(!move.ball.onBoard) {
			oS.remove(move.ball);
			oB.add(move.ball);
		}
		return new GameState(oB, oS);
	}
}

@@ -29,27 +29,24 @@
 va.util.
-Enum
+It
 erat
-ion
+or
 ;%0Aimport
@@ -177,38 +177,8 @@
 n;%0A%0A
-@SuppressWarnings(%22rawtypes%22)%0A
 publ
@@ -211,23 +211,30 @@
 nts 
-Enumeration
+Iterable%3CGameState%3E
  %7B%0A
-%09
 %0A%09Li
@@ -341,17 +341,16 @@
  score;%0A
-%09
 %0A%09public
@@ -443,24 +443,25 @@
 lls) %7B%0A%09%09%09if
+ 
 (ball.onBoar
@@ -523,25 +523,24 @@
 ll);%0A%09%09%7D%0A%09%7D%0A
-%09
 %0A%09public Gam
@@ -630,25 +630,24 @@
 onBoard;%0A%09%7D%0A
-%09
 %0A%09public int
@@ -675,25 +675,24 @@
 n score;%0A%09%7D%0A
-%09
 %0A%09public voi
@@ -723,17 +723,16 @@
 = a;%0A%09%7D%0A
-%09
 %0A%09public
@@ -788,32 +788,33 @@
 onBoard) %7B%0A%09%09%09if
+ 
 (ball.isMountabl
@@ -935,24 +935,25 @@
 os);%0A%09%09%09%09%09if
+ 
 (move.anyLin
@@ -1215,24 +1215,25 @@
 ard) %7B%0A%09%09%09if
+ 
 (ball.isRemo
@@ -1345,16 +1345,17 @@
 %7B%0A%09%09%09%09if
+ 
 (ball2 !
@@ -1499,138 +1499,138 @@
 %09%09%7D%0A
-%09%09
 %0A%09%7D%0A%0A%09
-@Override%0A%09public boolean hasMoreElements() %7B%0A%09%09return !moves.isEmpty();%0A%09%7D%0A%0A%09@Override%0A%09public GameState nextElement
+public Iterator%3CGameState%3E iterator() %7B%0A%09%09List%3CGameState%3E list = new LinkedList%3CGameState%3E();%0A%09%09while (!moves.isEmpty
 ()
+)
  %7B%0A
+%09
 %09%09Li
@@ -1650,16 +1650,17 @@
  balls;%0A
+%09
 %09%09List%3CB
@@ -1680,16 +1680,17 @@
 oard;%0A%09%09
+%09
 Move mov
@@ -1709,18 +1709,20 @@
 t(0);%0A%09%09
+%09
 if
+ 
 (move.re
@@ -1737,16 +1737,15 @@
 ) %7B%0A
-%09%09%09
 %0A
+%09
 %09%09%7D%0A
+%09
 %09%09mo
@@ -1759,16 +1759,17 @@
 ove(0);%0A
+%09
 %09%09move.b
@@ -1800,18 +1800,20 @@
 tion;%0A%09%09
+%09
 if
+ 
 (!move.b
@@ -1830,16 +1830,17 @@
 d) %7B%0A%09%09%09
+%09
 oS.remov
@@ -1853,16 +1853,17 @@
 .ball);%0A
+%09
 %09%09%09oB.ad
@@ -1882,19 +1882,23 @@
 ;%0A%09%09
+%09
 %7D%0A%09%09
-return 
+%09list.add(
 new 
@@ -1914,15 +1914,46 @@
 (oB, oS)
+);%0A%09%09%7D%0A%09%09return list.iterator()
 ;%0A%09%7D%0A%7D%0A

use Iterator instead of deprecated Enumeration