コード例 #1
0
ファイル: SimpleSnakeWorld.cs プロジェクト: Mawrte/snakeNEAT
        private void PlaceFood()
        {
            TwoDPoint fp = RandomPoint(_emptyTiles);

            _field[fp.X, fp.Y] = Tile.food;
            _emptyTiles.Remove(fp);

            _food.Add(fp);
        }
コード例 #2
0
        public override bool Equals(object obj)
        {
            if (obj == null || obj.GetType() != this.GetType())
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            TwoDPoint p = (TwoDPoint)obj;

            return(X == p.X && Y == p.Y);
        }
コード例 #3
0
ファイル: SimpleSnakeWorld.cs プロジェクト: Mawrte/snakeNEAT
        private void PlaceSnake()
        {
            _nextPos = RandomPoint(_emptyTiles);

            _snake = new Snake(_nextPos);

            DrawSnakeHeadOnTiles();

            for (int i = 0; i < SnakeStartingLength - 1; i++)
            {
                _nextPos = RandomPoint(GetAdjacent(_nextPos));
                _snake.Grow(_nextPos);
                DrawSnakeHeadOnTiles();
            }
        }
コード例 #4
0
ファイル: SimpleSnakeWorld.cs プロジェクト: Mawrte/snakeNEAT
        void MoveTo(TwoDPoint p)
        {
            if (_food.Contains(p))
            {
                _snake.Grow(p);
                _score++;
                _food.Remove(p);
            }
            else
            {
                _emptyTiles.Remove(p);
                _field[_snake.Tail.X, _snake.Tail.Y] = Tile.empty;
                _emptyTiles.Add(_snake.Tail);
                _snake.Move(p);
            }

            _field[p.X, p.Y] = Tile.snake;
        }
コード例 #5
0
ファイル: SimpleSnakeWorld.cs プロジェクト: Mawrte/snakeNEAT
 private bool isInvalid(TwoDPoint p)
 {
     return(p.X < 0 || p.Y < 0 || p.X >= Width || p.Y >= Height);
 }
コード例 #6
0
ファイル: SimpleSnakeWorld.cs プロジェクト: Mawrte/snakeNEAT
 private IEnumerable <TwoDPoint> GetAdjacent(TwoDPoint point)
 {
     return(_emptyTiles.Where(p => p.ManhattanDistance(point) == 1));
 }
コード例 #7
0
ファイル: Snake.cs プロジェクト: Mawrte/snakeNEAT
        //public void UnGrow()
        //{
        //    _points.RemoveAt(_points.Count - 1);
        //}

        public void Move(TwoDPoint p)
        {
            _points.Dequeue();
            _points.Enqueue(p);
        }
コード例 #8
0
ファイル: Snake.cs プロジェクト: Mawrte/snakeNEAT
 public void Grow(TwoDPoint p)
 {
     _points.Enqueue(p);
 }
コード例 #9
0
ファイル: Snake.cs プロジェクト: Mawrte/snakeNEAT
        public Snake(int x, int y)
        {
            TwoDPoint starting = new TwoDPoint(x, y);

            _points.Enqueue(starting);
        }
コード例 #10
0
ファイル: Snake.cs プロジェクト: Mawrte/snakeNEAT
 public Snake(TwoDPoint starting)
 {
     _points.Enqueue(starting);
 }
コード例 #11
0
ファイル: Snake.cs プロジェクト: Mawrte/snakeNEAT
        //readonly List<TwoDPoint> _points = new List<TwoDPoint>();

        public Snake()
        {
            TwoDPoint p = new TwoDPoint(0, 0);

            _points.Enqueue(p);
        }
コード例 #12
0
 public bool Equals(TwoDPoint p)
 {
     return(X == p.X && Y == p.Y);
 }
コード例 #13
0
 internal int ManhattanDistance(TwoDPoint p)
 {
     return(Math.Abs(_x - p.X) + Math.Abs(_y - p.Y));
 }