package se.kjellstrand.fiveinarow.game_model.players;

import se.kjellstrand.fiveinarow.game_model.FiveInARowBoard;
import se.kjellstrand.fiveinarow.game_model.Move;

/**
 * Created by carlemil on 2015-02-25.
 */
public class RandomPlayer extends AbstractPlayer {
    @Override
    public String getName() {
        return "RNDP";
    }

    public RandomPlayer(int _playerNumber) {
        super(_playerNumber);
    }

    @Override
    public Move getNextMove(FiveInARowBoard board) {
        Move move = new Move();
        int attempt = 0;
        do {
            move.x = (int) (Math.random() * board.getWidth());
            move.y = (int) (Math.random() * board.getHeight());
        } while (!board.isMoveLegal(move) && attempt++ < 100);

        return move;
    }
}

@@ -524,81 +524,63 @@
     
-int attempt
+double currentMaxRnd
  = 0
+f
 ;%0A
-        do %7B%0A            move.x = (int) (Math.random() *
+%0A        for (int y = 0; y %3C
  boa
@@ -592,18 +592,24 @@
 tWidth()
-)
 ;
+ y++) %7B
 %0A       
@@ -617,78 +617,74 @@
     
-move.y = (int) (Math.random() * board.getHeight());%0A        %7D while
+for (int x = 0; x %3C board.getHeight(); x++) %7B%0A                if
  (
-!
 boar
@@ -701,34 +701,292 @@
 gal(
-move) && attempt++ %3C 100);
+x, y)) %7B%0A                    double rnd = Math.random();%0A                    if (rnd %3E currentMaxRnd) %7B%0A                        currentMaxRnd = rnd;%0A                        move.x = x;%0A                        move.y = y;%0A                    %7D%0A                %7D%0A            %7D%0A        %7D
 %0A%0A  

fix minor bug in randomplayer