public void UpdateBoard(Cordinate cords)
        {
            var cordinate = Status.CurrentBoard.Cordinates.Single(x => x.X == cords.X && x.Y == cords.Y);

            cordinate.IsOccupied = true;
            cordinate.Symbol     = Status.CurrentPlayer.Symbol;
        }
Beispiel #2
0
 private IEnumerable<Cordinate> FindMoves(Cordinate currentPosition, IEnumerable<Cordinate> currentPlayer, IEnumerable<Cordinate> opposingPlayer)
 {
     return from direction in FindPossibleDirections(currentPosition, opposingPlayer)
            let pos = SearchDirection(currentPosition, direction, currentPlayer, opposingPlayer)
            where pos != null
            select pos;
 }
Beispiel #3
0
 private IEnumerable <Cordinate> FindMoves(Cordinate currentPosition, IEnumerable <Cordinate> currentPlayer, IEnumerable <Cordinate> opposingPlayer)
 {
     return(from direction in FindPossibleDirections(currentPosition, opposingPlayer)
            let pos = SearchDirection(currentPosition, direction, currentPlayer, opposingPlayer)
                      where pos != null
                      select pos);
 }
        private void UpdateGridStatus(Cordinate cords)
        {
            var cordinate = Cordinates.Single(x => x.X == cords.X && x.Y == cords.Y);

            cordinate.IsOccupied = true;
            cordinate.Symbol     = cords.Symbol;
        }
 public void Update(Cordinate cords)
 {
     if (!IsOccupied(cords))
     {
         UpdateGridStatus(cords);
     }
 }
Beispiel #6
0
        public List <Cordinate> GetRouteCoordinatesInformation(int routeId)
        {
            List <Cordinate> cordinates = new List <Cordinate>();

            try
            {
                using (HttpClient httpClient1 = new HttpClient())
                {
                    httpClient1.BaseAddress = new Uri("http://sanjayjdm.apphb.com/");
                    httpClient1.DefaultRequestHeaders.Accept.Clear();
                    httpClient1.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
                    string    jsonResponseString = httpClient1.GetStringAsync("api/getroutecordinates?appKey=ttpapikey.asxc123nju89mno0&routeId=" + routeId.ToString()).Result;
                    string    jsonwithDouble     = jsonResponseString.Replace("'", "\"");
                    XDocument doc      = XDocument.Parse(jsonwithDouble);
                    string    pureJson = doc.Root.Value;

                    var coordinates = Newtonsoft.Json.Linq.JObject.Parse(pureJson).SelectToken("cordinates").ToObject <List <Cordinate> >();

                    foreach (var coordinate in coordinates)
                    {
                        Cordinate cordinate = new Cordinate();
                        cordinate.seqNo    = coordinate.seqNo;
                        cordinate.startLat = coordinate.startLat;
                        cordinate.startLon = coordinate.startLon;
                        coordinates.Add(cordinate);
                    }
                }
            }
            catch (Exception exep)
            {
                throw new Exception(exep.Message);
            }
            return(cordinates);
        }
Beispiel #7
0
        public string ConvertCordinatesToFieldDescription(Cordinate cord)
        {
            var column = (char)('A' + cord.X);
            var row    = (cord.Y + 1).ToString();

            return(column + row);
        }
Beispiel #8
0
    public void CreateRoom()
    {
        /** Create room inside the maze
         * for (int i = 3; i < 7; i++)
         * {
         *   for(int j = 3; j < 7; j++)
         *   {
         *       //select the middle area to generate boos room, will have more settings to change size and location and number of rooms in next patch.
         *       Cordinate cor = new Cordinate(i, j);
         *       MazeCell curr = GetCell(cor); // Get maze cell by i,j
         *       if (i > 3 && j > 3 && i < 6 && j < 6)
         *       {
         *           // all the mazecell inside the room, we should delete the edge to the neibour
         *           for (int k = 0; k < 4; k++)
         *           {
         *               MazeCellEdge edge = curr.GetEdge((MazeDirection)k);
         *               Debug.Log(i + "," + j + "," + k + "," + edge.GetEdgeType() + "\n");
         *               string edgeType = edge.GetEdgeType();
         *               if (edgeType.Equals("Wall"))
         *               {
         *                   Debug.Log("deleting"+i+","+j);
         *                   curr.DeleteEdge((MazeDirection)k);
         *               }
         *           }
         *       }
         *   }
         * }*/



        // Create a boss room outside the maze .
        Cordinate cor;
        MazeCell  cell;

        for (int i = 0; i < sizeZ; i++)
        {
            for (int j = 0; j < sizeX; j++)
            {
                cor = new Cordinate(sizeZ + i, j);
                CreateCell(cor);
            }
        }
        for (int i = 0; i < sizeZ; i++)
        {
            cor  = new Cordinate(sizeZ + i, 0);
            cell = GetCell(cor);
            CreateWall(cell, null, MazeDirection.South);
            cor  = new Cordinate(sizeZ + i, sizeX - 1);
            cell = GetCell(cor);
            CreateWall(cell, null, MazeDirection.North);
        }
        for (int i = 0; i < sizeX; i++)
        {
            cor  = new Cordinate(2 * sizeZ - 1, i);
            cell = GetCell(cor);
            CreateWall(cell, null, MazeDirection.East);
        }
        // CreateBoss(sizeX,0);
    }
Beispiel #9
0
        public string GetOutput(Cordinate <T> cordinate, IDirection <T, U> direction)
        {
            string name          = direction.GetType().Name;
            int    index         = name.IndexOf('`');
            var    directionName = index == -1 ? name : name.Substring(0, index);

            return($"{cordinate.X},{cordinate.Y},{directionName.ToUpper()}");
        }
Beispiel #10
0
    private void Spawn()
    {
        print("spawn");
        //randomly spawn in the maze
        Cordinate cordinate = maze.RandomCordinate;

        this.transform.position = new Vector3(cordinate.x - maze.sizeX * 0.5f + 0.5f, 0f, cordinate.z - maze.sizeZ * 0.5f + 0.5f);
    }
Beispiel #11
0
        public Block(Tetris tetris)
        {
            this.tetris = tetris;

            hitbox = tetris.collisions[new System.Random().Next(0, tetris.collisions.Length)];

            cordinate = new Cordinate(new System.Random().Next(0, tetris.Width - hitbox.Width + 1), -hitbox.Height + 1);
        }
Beispiel #12
0
    public void OpenDoor()
    {
        Cordinate cor  = new Cordinate(9, 5);
        MazeCell  cell = GetCell(cor);

        cell.DeleteEdge(MazeDirection.East);
        isDoorOpen = true;
    }
        public void GameBoardUpdateTest()
        {
            var cords = new Cordinate(3, 3, 'X');

            _gameBoard.Update(cords);
            Assert.AreEqual(_gameBoard.Cordinates.Count(x => x.IsOccupied == false), 8);
            Assert.AreEqual(_gameBoard.Cordinates.Count(x => x.IsOccupied), 1);
            Assert.AreEqual(_gameBoard.Cordinates.Single(x => x.X == cords.X && x.Y == cords.Y).Symbol, 'X');
        }
Beispiel #14
0
 public void Initialize(MazeCell source, MazeCell sink, MazeDirection direction)
 {
     this.source    = source;
     this.sink      = sink;
     this.direction = direction.toCordinate();
     source.SetEdge(direction, this);
     transform.parent        = source.transform;
     transform.localPosition = Vector3.zero;
     transform.rotation      = direction.ToRotation();
 }
        public void GameBoardResetTest()
        {
            var cords = new Cordinate(3, 3, 'X');

            _gameBoard.Update(cords);
            _gameBoard.Reset();
            Assert.AreEqual(_gameBoard.Cordinates.Count(), 9);
            Assert.AreEqual(_gameBoard.Cordinates.Count(x => x.IsOccupied == false), 9);
            Assert.AreEqual(_gameBoard.Cordinates.Count(x => x.Symbol == '*'), 9);
        }
Beispiel #16
0
        public GameMove ToGameMove(Cordinate cordinate, Color color)
        {
            var result = new GameMove()
            {
                RowIndex      = cordinate.Row,
                ColumnIndex   = cordinate.Column,
                ColorInString = color == Color.White ? "white" : "black"
            };

            return(result);
        }
Beispiel #17
0
        private List <Cordinate> GetEmptyNeightbours(Cordinate cord)
        {
            List <Cordinate> freeNeightBours =
                cord.GetNeightbours().Where(c => c.X >= 0 &&
                                            c.X < Width &&
                                            c.Y >= 0 &&
                                            c.Y < Height &&
                                            Board[c.Y][c.X].State == FieldStateEnum.Empty).ToList();

            return(freeNeightBours);
        }
Beispiel #18
0
    public bool Equals(Cordinate c)
    {
        // If parameter is null return false:
        if ((object)c == null)
        {
            return false;
        }

        // Return true if the fields match:
        return (this.X == c.X) && (this.Y == c.Y);
    }
Beispiel #19
0
        public Cordinate <T> Move(Cordinate <T> current, U step, T xLimit, T yLimit)
        {
            if ((dynamic)current.Y >= (dynamic)yLimit)
            {
                return(current);
            }

            return(new Cordinate <T>
            {
                X = (dynamic)current.X,
                Y = (dynamic)current.Y + (dynamic)step
            });
        }
Beispiel #20
0
        public Cordinate <T> Move(Cordinate <T> current, U step, T xLimit, T yLimit)
        {
            if ((dynamic)current.X <= 0)
            {
                return(current);
            }

            return(new Cordinate <T>
            {
                X = (dynamic)current.X - (dynamic)step,
                Y = current.Y
            });
        }
Beispiel #21
0
        Cordinate <T> IDirection <T, U> .Move(Cordinate <T> current, U step, T xLimit, T yLimit)
        {
            if ((dynamic)current.X >= (dynamic)xLimit)
            {
                return(current);
            }

            return(new Cordinate <T>
            {
                X = (dynamic)current.X + (dynamic)step,
                Y = current.Y
            });
        }
Beispiel #22
0
 private IEnumerable<Cordinate> FindPossibleDirections(Cordinate pos, IEnumerable<Cordinate> opposingPlayer)
 {
     for (int x = pos.X - 1; x <= pos.X + 1; x++)
     {
         for (int y = pos.Y - 1; y <= pos.Y + 1; y++)
         {
             if (opposingPlayer.Any(p => p.X == x && p.Y == y))
             {
                 yield return new Cordinate() { X = x - pos.X, Y = y - pos.Y };
             }
         }
     }
 }
Beispiel #23
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            List <Cordinate> cordinateList = Fill(20);

            foreach (var VARIABLE in cordinateList)
            {
                Console.WriteLine($"[{VARIABLE.x},{VARIABLE.y}]");
            }
            Cordinate source = new Cordinate(25, 25);
            Cordinate cordinateWithMaxDistance = Closest(source, cordinateList);

            Console.WriteLine($"minDistance : [{cordinateWithMaxDistance.x}, {cordinateWithMaxDistance.y}]");
        }
Beispiel #24
0
 private IEnumerable <Cordinate> FindPossibleDirections(Cordinate pos, IEnumerable <Cordinate> opposingPlayer)
 {
     for (int x = pos.X - 1; x <= pos.X + 1; x++)
     {
         for (int y = pos.Y - 1; y <= pos.Y + 1; y++)
         {
             if (opposingPlayer.Any(p => p.X == x && p.Y == y))
             {
                 yield return(new Cordinate()
                 {
                     X = x - pos.X, Y = y - pos.Y
                 });
             }
         }
     }
 }
Beispiel #25
0
    private MazeCell CreateCell(Cordinate cordinate)
    {
        // Create the cell instance and gameobject
        // location = (x,0,z), x is the numer the of cells in a row and z is column.
        MazeCell newCell = Instantiate(cellPrefab) as MazeCell;

        cells[cordinate.x, cordinate.z] = newCell;
        newCell.cordinate        = cordinate;
        newCell.name             = "Maze Cell" + cordinate.x + "," + cordinate.z;
        newCell.transform.parent = transform;
        // transform x,z into actual value.
        newCell.transform.localPosition = new Vector3(cordinate.x - sizeX * 0.5f + 0.5f, 0f, cordinate.z - sizeZ * 0.5f + 0.5f);
        // BakerNavMesh baker = new BakerNavMesh();
        // baker.GenerateNavMeshSurface();
        return(newCell);
    }
Beispiel #26
0
        private CordinateSet GetRowCordinates(int rowNumber)
        {
            var winningCordinates = new CordinateSet();

            for (var c = 1; c <= GRID_WIDTH; c++)
            {
                var cords = new Cordinate
                {
                    X = rowNumber,
                    Y = c
                };
                winningCordinates.Set(cords);
            }

            return(winningCordinates);
        }
        private static IList <Cordinate> InitializeGrid(int _length, int _height, char symbol)
        {
            var cordinates = new List <Cordinate>();

            for (var i = 1; i <= _length; i++)
            {
                for (var j = 1; j <= _height; j++)
                {
                    var cord = new Cordinate(i, j, symbol)
                    {
                        IsOccupied = false
                    };
                    cordinates.Add(cord);
                }
            }
            return(cordinates);
        }
Beispiel #28
0
        private CordinateSet GetColumnCordinates(int columnNumber)
        {
            var winningCordinates = new CordinateSet();

            for (var r = 1; r <= GRID_HEIGHT; r++)
            {
                var cords =
                    new Cordinate
                {
                    X = r,
                    Y = columnNumber
                };
                winningCordinates.Set(cords);
            }

            return(winningCordinates);
        }
Beispiel #29
0
        public static Cordinate Closest(Cordinate source, List <Cordinate> cordinates)
        {
            double distance;
            Dictionary <Cordinate, double> myDictionary = new Dictionary <Cordinate, double>();

            foreach (var cordinate in cordinates)
            {
                distance = Math.Sqrt(Math.Pow(cordinate.x - source.x, 2) + Math.Pow(cordinate.y - source.y, 2));
                Console.WriteLine(distance);
                myDictionary.Add(cordinate, distance);
            }

            var max = myDictionary.Aggregate((l, r) => l.Value < r.Value ? l : r).Key;

            Console.WriteLine("min distance is" + myDictionary.Values.Min().ToString());
            //  quastion is, what if the maxvalue-key pair is not unique;
            return(max);
        }
Beispiel #30
0
        private void ProcessInitialPlacement(string command)
        {
            var commandSegments = RoboHelper.GetCommandSegments(command);

            //this will throw exception if the commads are invalid
            //This is done this way so that the detail error messages are captured for ease of user
            RoboHelper.IsCommandLineArgumentsValid(commandSegments);

            //Check if the original cordinate is valid
            RoboHelper.IsCordinateValid <T>(commandSegments, MoveArea);

            //set the initial position
            Position = new Cordinate <T>
            {
                X = (T)Convert.ChangeType(commandSegments.X, typeof(T)),
                Y = (T)Convert.ChangeType(commandSegments.Y, typeof(T))
            };
            //set the initial direction
            Direction = DirectionFactory <T, U> .Create(commandSegments.Direction);
        }
Beispiel #31
0
        private void InsertCordinateMetadata(Guid wardId, IList <CordinatePoint> cordinates, DataAccessDataContext context)
        {
            IList <Cordinate> cordinateList = new List <Cordinate>();

            foreach (var cordinate in cordinates)
            {
                Cordinate cordinatePoint = new Cordinate
                {
                    Id        = Guid.NewGuid(),
                    Latitude  = cordinate.Latitude,
                    Longitude = cordinate.Longitude,
                    WardId    = wardId,
                    Rank      = cordinate.Rank
                };

                cordinateList.Add(cordinatePoint);
            }

            context.Cordinates.InsertAllOnSubmit(cordinateList.AsEnumerable());
            SubmitData();
        }
Beispiel #32
0
        public void Action_Compute_Cordinate_Should_Return_Same_Cordinate(string command, int x, int y)
        {
            var moveAreaMock = new Mock <IMoveArea <int> >();

            moveAreaMock.SetupGet(s => s.Width).Returns(It.IsAny <int>);
            moveAreaMock.SetupGet(s => s.Height).Returns(It.IsAny <int>);

            var directionMock = new Mock <IDirection <int, int> >();

            directionMock.Setup(s => s.NextFacing(It.IsAny <IAction <int, int> >())).Returns(new East <int, int>());

            var action = ActionFactory <int, int> .Create(command);

            var cordinate = new Cordinate <int>
            {
                X = x,
                Y = y
            };
            var result = action.ComputeNewCordinate(cordinate, 1, moveAreaMock.Object, directionMock.Object);

            result.Should().BeSameAs(cordinate);
        }
Beispiel #33
0
        public void Horizontal_East_Move_Action_Compute_Cordinate_Should_Return_Correct_New_Cordinate(string command, string directi, int x, int y, int exX, int exY, int step)
        {
            var moveAreaMock = new Mock <IMoveArea <int> >();

            moveAreaMock.SetupGet(s => s.Width).Returns(10);
            moveAreaMock.SetupGet(s => s.Height).Returns(10);

            var direction = DirectionFactory <int, int> .Create(directi);

            var action = ActionFactory <int, int> .Create(command);

            var cordinate = new Cordinate <int>
            {
                X = x,
                Y = y
            };

            var result = action.ComputeNewCordinate(cordinate, step, moveAreaMock.Object, direction);

            result.X.Should().Be(exX);
            result.Y.Should().Be(exY);
        }
 static int BreadthFirstSearch(int[,] arr, int k, int l)
 {
     int[,] arr2 = new int[arr.GetLength(0), arr.GetLength(1)];
     Queue<Cordinate> que = new Queue<Cordinate>();
     int count = 1;
     Cordinate t = new Cordinate();
     Cordinate z = new Cordinate();
     t.x = k;
     t.y = l;
     que.Enqueue(t);
     arr2[k, l] = -1;
     while (que.Count != 0)
     {
         t = que.Dequeue();
         if ((t.x - 1) >= 0)
         {
             if (arr[t.x - 1, t.y] == arr[t.x, t.y] && arr2[t.x - 1, t.y] != -1)
             {
                 z.x = t.x - 1;
                 z.y = t.y;
                 que.Enqueue(z);
                 arr2[t.x - 1, t.y] = -1;
                 count++;
             }
         }
         if ((t.x + 1) < arr.GetLength(0))
         {
             if (arr[t.x + 1, t.y] == arr[t.x, t.y] && arr2[t.x + 1, t.y] != -1)
             {
                 z.x = t.x + 1;
                 z.y = t.y;
                 que.Enqueue(z);
                 arr2[t.x + 1, t.y] = -1;
                 count++;
             }
         }
         if ((t.y - 1) >= 0)
         {
             if (arr[t.x, t.y - 1] == arr[t.x, t.y] && arr2[t.x, t.y - 1] != -1)
             {
                 z.x = t.x;
                 z.y = t.y - 1;
                 que.Enqueue(z);
                 arr2[t.x, t.y - 1] = -1;
                 count++;
             }
         }
         if ((t.y + 1) < arr.GetLength(1))
         {
             if (arr[t.x, t.y + 1] == arr[t.x, t.y] && arr2[t.x, t.y + 1] != -1)
             {
                 z.x = t.x;
                 z.y = t.y + 1;
                 que.Enqueue(z);
                 arr2[t.x, t.y + 1] = -1;
                 count++;
             }
         }
     }
     return count;
 }
Beispiel #35
0
 public MapPosition(int x, int y, Const.Team team)
 {
     this._cordinate = new Cordinate(x, y);
     this.Team = team;
 }
Beispiel #36
0
        private Cordinate SearchDirection(Cordinate currentPosition, Cordinate direction, IEnumerable<Cordinate> currentPlayer, IEnumerable<Cordinate> opposingPlayer)
        {
            var currentX = currentPosition.X;
            var currentY = currentPosition.Y;

            while (currentX >= 0 && currentX <= 7 && currentY >= 0 && currentY <= 7)
            {
                currentX += direction.X;
                currentY += direction.Y;

                if (!opposingPlayer.Any(p => p.X == currentX && p.Y == currentY))
                {
                    if (!currentPlayer.Any(p => p.X == currentX && p.Y == currentY))
                    {
                        return new Cordinate() { X = currentX, Y = currentY };
                    }
                }
            }

            return null;
        }