Example #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Newtonsoft.Json.Linq.JObject o = Newtonsoft.Json.Linq.JObject.Load(reader);
            int       size          = o.Value <int>("Size");
            PieceGrid newPieceGrid  = new PieceGrid(size);
            var       pieceGridJson = o.Value <JObject>("PointPieces");
            Dictionary <Point, Piece> pointPiecesDictionary = new Dictionary <Point, Piece>();

            foreach (KeyValuePair <string, JToken> kvp in pieceGridJson)
            {
                Point point = Point.Get(kvp.Key);
                Piece piece = Piece.Get(kvp.Value.Value <string>());
                pointPiecesDictionary.Add(point, piece);
            }
            newPieceGrid.Initialize(pointPiecesDictionary);
            return(newPieceGrid);
        }
Example #2
0
        public Board ImagineWinningBoard(Board board)
        {
            List <Point> twoByTwos = board.PieceGrid.GetEmpyTwoByTwos().ToList();
            List <Point> pockets   = new List <Point>();
            Random       rnd       = new Random();

            while (pockets.Count < 7)
            {
                foreach (Point p in twoByTwos)
                {
                    if (rnd.NextDouble() > .9d)
                    {
                        pockets.Add(p);
                        for (int x = -1; x < 2; x++)
                        {
                            for (int y = -1; y < 2; y++)
                            {
                                Point removePoint = p + Point.Get(x, y);
                                if (!board.PieceGrid.IsOutOfBounds(removePoint))
                                {
                                    twoByTwos.Remove(removePoint);
                                }
                            }
                        }
                        break;
                    }
                }
            }

            Board winningBoard = board.Clone();
            Owner owner        = PlayingAs;

            foreach (Point p in pockets)
            {
                List <int> a = new List <int> {
                    rnd.Next(), rnd.Next(), rnd.Next(), rnd.Next()
                };
                int index = a.IndexOf(a.Max());

                switch (index)
                {
                case 0:
                    winningBoard.PieceGrid.PointPieces[p] = Piece.Get(PieceName.Amazon, owner);
                    break;

                case 1:
                    winningBoard.PieceGrid.PointPieces[p + Point.Get(1, 0)] = Piece.Get(PieceName.Amazon, owner);
                    break;

                case 2:
                    winningBoard.PieceGrid.PointPieces[p + Point.Get(0, 1)] = Piece.Get(PieceName.Amazon, owner);
                    break;

                case 3:
                    winningBoard.PieceGrid.PointPieces[p + Point.Get(1, 1)] = Piece.Get(PieceName.Amazon, owner);
                    break;
                }


                Owner arrowOwner = board.CurrentPlayer;
                arrowOwner = arrowOwner == Owner.Player1 ? Owner.Player2 : Owner.Player1;


                owner = owner == Owner.Player1 ? Owner.Player2 : Owner.Player1;
            }


            throw new NotImplementedException();
        }