public void BoardNoTurnsAtAlreadyOccupiedPosition()
 {
     Board b = new Board();
     Position p = new Position(2, 6);
     b[p] = Side.Cross;
     b[p] = Side.Cross;
 }
 public void BoardNoTurnsAtAlreadyOccupiedPositionByEnemy()
 {
     Board b = new Board();
     Position p = new Position(9, 3);
     b[p] = Side.Cross;
     b[p] = Side.Zero;
 }
Beispiel #3
0
 public SimplePlayer(Side s, Board b, int level)
     : this(s, level)
 {
     foreach (Turn turn in b.Turns)
     {
         undoList.Push(state.Advance(turn.position, turn.side));
     }
 }
Beispiel #4
0
 public MachinePlayer(Board board, Side side, int level  )
 {
     playerAI = new SimplePlayer(side, board, level);
     timeToMakeTheTurn = ( side == CoreCZ.Side.Cross );
     this.board = board;
     this.side = side;
     this.level = level;
 }
        public void BoardGetBoundingBoxEmptyBoard()
        {
            Board b = new Board();

            Area a = b.BoundingBox;
            Confirm.IsTrue(a.sw.row > a.ne.row);
            Confirm.IsTrue(a.sw.column > a.ne.column);
        }
Beispiel #6
0
        public HumanPlayer(Board board, string name, Side side)
        {
            this.board = board;
            this.name = name;
            this.side = side;

            // Enable tap gestures
            TouchPanel.EnabledGestures = TouchPanel.EnabledGestures | GestureType.Tap;
        }
        public void BoardGetBoundingBox()
        {
            Board b = new Board();
            b[new Position(0, 0)] = Side.Cross;
            b[new Position(4, 2)] = Side.Zero;
            b[new Position(-2, 2)] = Side.Cross;
            b[new Position(0, 6)] = Side.Zero;
            b[new Position(-1, -1)] = Side.Cross;

            Area a = b.BoundingBox;
            Confirm.IsTrue(a.sw.row == -2);
            Confirm.IsTrue(a.sw.column == -1);
            Confirm.IsTrue(a.ne.row == 4);
            Confirm.IsTrue(a.ne.column == 6);
        }
        public void BoardLastPosition()
        {
            Board b = new Board();
            Position p = new Position(0, 0);
            b[p] = Side.Cross;
            Confirm.Equal(b.LastPosition, p);

            p = new Position(4, 2);
            b[p] = Side.Zero;
            Confirm.Equal(b.LastPosition, p);

            p = new Position(-4, 3);
            b[p] = Side.Cross;
            Confirm.Equal(b.LastPosition, p);

            p = new Position(5, -21);
            b[p] = Side.Zero;
            Confirm.Equal(b.LastPosition, p);

            p = new Position(0, 2);
            b[p] = Side.Cross;
            Confirm.Equal(b.LastPosition, p);
        }
Beispiel #9
0
        public static GameControler Load()
        {
            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
            if ( !settings.Contains("Saved") || settings["Saved"].ToString() == false.ToString())
            {
                return null;
            }

            Board board = new Board();
            GameControler ctrl;
            try
            {
                using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (IsolatedStorageFileStream isoStream = store.OpenFile(@"board.dat", FileMode.Open))
                    {
                        BinaryReader br = new BinaryReader(isoStream);
                        board.Deserialize(br);
                        br.Close();
                    }
                }
                ctrl = new GameControler(board);

                ctrl.SetUpGame(parseType(settings["Game.Player1"].ToString()), parseType(settings["Game.Player2"].ToString()));

                if (settings["Game.CurrentTurnFrom"].ToString() == 1.ToString())
                {
                    ctrl.currentPlayer = ctrl.player1;
                }
                else
                {
                    ctrl.currentPlayer = ctrl.player2;
                }

                return ctrl;
            }
            catch (Exception)
            {
                return null;
            }
        }
Beispiel #10
0
 private GameControler(Board board)
 {
     gameBoard = board;
 }
Beispiel #11
0
 public GameControler()
 {
     gameBoard = new Board();
 }
Beispiel #12
0
        static void test_performance(int runs = 10)
        {
            CoreCZ.AI.SimpleCostFuntcion.startProfiling = start;
            CoreCZ.AI.SimpleCostFuntcion.endProfiling = stop;

            double[] times = new double[runs];

            for (int i = 0; i < runs; ++i)
            {
                Board board = new Board();
                SimplePlayer cross = new SimplePlayer(Side.Cross, 2);
                SimplePlayer zero = new SimplePlayer(Side.Zero, 2);

                int counter = 0;
                Console.Write("{0:D2}", i);
                var start_time = DateTime.Now;
                while (counter < 12)
                {

                    Position p = cross.MakeNextTurn();
                    board[p] = Side.Cross;
                    counter++;
                    Console.Write(".");
                    if (board.Winner) break;
                    zero.EnemyTurn(p);

                    p = zero.MakeNextTurn();
                    board[p] = Side.Zero;
                    counter++;
                    Console.Write(".");
                    if (board.Winner) break;
                    cross.EnemyTurn(p);
                }
                Console.WriteLine();
                times[i] = (DateTime.Now - start_time).TotalMilliseconds;
            }

            var max_time = times.Max() / 1000;
            var min_time = times.Min() / 1000;
            var avg_time = times.Average() / 1000;

            Console.WriteLine("Average time: {0:F3}", avg_time);
            Console.WriteLine("    max time: {0:F3}", max_time);
            Console.WriteLine("    min time: {0:F3}", min_time);

            Console.WriteLine("SimpleCostFunction: {0:F3}", costFunctionTimer.ElapsedMilliseconds/1000.0);
            Console.WriteLine("SimpleCostFunction: {0} calls, {1} cache hits", SimpleCostFuntcion.calls, SimpleCostFuntcion.cache_hits);
        }
Beispiel #13
0
        public void BoardSetAndGetPosAtDifferentQuadrants()
        {
            List<Position> testPositions = new List<Position>() {
                                               new Position(0, 0),
                                               new Position(0, 6),
                                               new Position(5, 12),
                                               new Position(7, 0),
                                               new Position(0, -3),
                                               new Position(-2, -4),
                                               new Position(-8, 0),
                                               new Position(-6, 4),
                                               new Position(4, -6)
                                           };

            foreach(Position p in testPositions)
            {
                Board b = new Board();
                b[p] = Side.Cross;
                Confirm.Equal(b[p], Side.Cross);
            }
        }
Beispiel #14
0
        public void BoardUndo()
        {
            Board b = new Board();
            Position p0 = new Position(0, 0);
            b[p0] = Side.Cross;

            Position p1 = new Position(4, 2);
            b[p1] = Side.Zero;

            Position p2 = new Position(-4, 3);
            b[p2] = Side.Cross;

            Position p3 = new Position(5, -21);
            b[p3] = Side.Zero;

            Position p4 = new Position(0, 2);
            b[p4] = Side.Cross;

            Confirm.IsTrue(b.Undo());
            Confirm.Equal(Side.Nobody, b[p4]);

            Confirm.IsTrue(b.Undo());
            Confirm.Equal(Side.Nobody, b[p3]);

            Confirm.IsTrue(b.Undo());
            Confirm.Equal(Side.Nobody, b[p2]);

            Confirm.IsTrue(b.Undo());
            Confirm.Equal(Side.Nobody, b[p1]);

            Confirm.IsTrue(b.Undo());
            Confirm.Equal(Side.Nobody, b[p0]);

            Confirm.IsFalse(b.Undo());
        }
Beispiel #15
0
 public TurnsLayer(ContentManager contentManager, Board gameBoard, Vector2 drawSize)
 {
     content = contentManager;
     board = gameBoard;
     this.drawSize = drawSize;
 }