source: java/ecj/games/league/RandomPerformanceMeter.java @ 1254

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

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1package games.league;
2
3import ec.util.MersenneTwisterFast;
4import games.Player;
5import games.scenarios.GameScenario;
6import games.scenarios.RandomizedTwoPlayersGameScenario;
7
8import java.io.InputStream;
9import java.util.Scanner;
10
11import cecj.app.othello.OthelloBoard;
12import cecj.app.othello.OthelloGame;
13import cecj.app.othello.OthelloPlayer;
14
15
16public class RandomPerformanceMeter {
17
18        private OthelloPlayer player;
19
20
21        public void readPlayer(InputStream input) {
22                Scanner s = new Scanner(input);
23                double[] wpc = new double[64];
24                for (int i = 0; i < 64; i++) {
25                        wpc[i] = s.nextDouble();
26                }
27                player = new OthelloPlayer(wpc);       
28               
29                System.out.println("Player = " + player);
30        }
31
32
33        private int testPlayer(int repeats) {
34                MersenneTwisterFast rng = new MersenneTwisterFast(System.currentTimeMillis());
35               
36                GameScenario scenario1 = new RandomizedTwoPlayersGameScenario(rng, new Player[] { player, new OthelloPlayer()}, new double[] {0, 1.0});
37                GameScenario scenario2 = new RandomizedTwoPlayersGameScenario(rng, new Player[] { new OthelloPlayer(), player}, new double[] {1.0, 0});
38                OthelloGame game = new OthelloGame(new OthelloBoard());
39               
40                int sum = 0;
41                for (int i = 0; i < repeats; i++) {
42                        game.reset();
43                        sum += ((scenario1.play(game) > 0) ? 1 : 0);
44                        game.reset();
45                        sum += ((scenario2.play(game) < 0) ? 1 : 0);
46                }
47               
48                return sum;
49        }
50       
51        /**
52         * @param args
53         */
54        public static void main(String[] args) {
55                RandomPerformanceMeter rpm = new RandomPerformanceMeter();
56                rpm.readPlayer(System.in);
57                System.out.println(rpm.testPlayer(500) + " games won out of 1000");
58        }
59
60       
61}
Note: See TracBrowser for help on using the repository browser.