source: java/ecj/games/scenarios/SimpleTwoPlayersGameScenario.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 817 bytes
Line 
1package games.scenarios;
2
3import games.BoardGame;
4import games.GameMove;
5import games.Player;
6
7import java.util.List;
8
9public class SimpleTwoPlayersGameScenario implements GameScenario {
10
11        private Player[] players;
12
13        public SimpleTwoPlayersGameScenario(Player[] players) {
14                this.players = players;
15        }
16
17        public int play(BoardGame game) {
18                while (!game.endOfGame()) {
19                        List<? extends GameMove> moves = game.findMoves();
20                        if (!moves.isEmpty()) {
21                                GameMove bestMove = null;
22                                double bestEval = Double.NEGATIVE_INFINITY;
23                                for (GameMove move : moves) {
24                                        double eval = game.evalMove(players[game.getCurrentPlayer()], move);
25                                        if (eval > bestEval) {
26                                                bestEval = eval;
27                                                bestMove = move;
28                                        }
29                                }
30                                game.makeMove(bestMove);
31                        }
32                        game.switchPlayer();
33                }
34                return game.getOutcome();
35        }
36}
Note: See TracBrowser for help on using the repository browser.