Esempio n. 1
0
    Vector3 pointPos; //position to place each prefab along the given circle/eliptoid

    #endregion Fields

    #region Constructors

    public BoardCircle()
    {
        Matrix = new CellState[SIZE_X, SIZE_Y];

        for (int x = 0; x < SIZE_X; x++) {
            for (int y = 0; y < SIZE_Y; y++) {
                //multiply 'i' by '1.0f' to ensure the result is a fraction
                float pointNum = (x*1.0f)/SIZE_X;
                //angle along the unit circle for placing points
                float angle = pointNum*Mathf.PI*2;

                 float X = Mathf.Sin (angle)*radiusX; // for radial placement and simple height
                 float Y = Mathf.Cos (angle)*radiusY; // for radial placement and simple height
                //float X = Mathf.Sin (angle)*(radiusX + radiusOffset* y); // for placement in a ring like fasion on the ground
                //float Y = Mathf.Cos (angle)*(radiusY + radiusOffset* y); // for placement in a ring like fasion on the ground

                //position for the point prefab
                if(vertical)
                    pointPos = new Vector3(X, Y)+centerPos;
                else if (!vertical){
                    pointPos = new Vector3(X, y*SCALE- (SIZE_Y / 2)*SCALE, Y)+centerPos; // for centered pivot of the entire group
                    pointPos = new Vector3(X, y*SCALE, Y)+centerPos; // for placement from bottom to top
                    //pointPos = new Vector3(X, centerPos.y, Y)+centerPos; // for placement in a ring like fasion on the ground
                }
                //var position = new Vector3(x - (SIZE_X / 2), y - (SIZE_Y / 2), 0);
                //var position = new Vector3(x*SCALE- (SIZE_X / 2)*SCALE,y*SCALE- (SIZE_Y / 2)*SCALE,0);
                var position = pointPos;
                Matrix[x, y] = CellFactory.Create(position, Random.Range(1, 3) == 1);
            }
        }
    }
Esempio n. 2
0
        public CellularAutomaton(int width, int height, Ruleset ruleset, float startNoise, bool aliveBorders)
        {
            this.width = width;
            this.height = height;
            this.ruleset = ruleset;
            this.aliveBorders = aliveBorders;
            cells = new CellState[width, height];
            copy = new CellState[width, height];

            visitAliveBorders = (int neighbourX, int neighbourY) =>
            {
                if (copy.IsInBounds(neighbourX, neighbourY))
                {
                    if (copy[neighbourX, neighbourY] == CellState.Alive)
                    {
                        aliveNeighbours++;
                    }
                }
                else
                {
                    aliveNeighbours++;
                }
            };
            visitDeadBorders = (int neighbourX, int neighbourY) =>
            {
                if (copy[neighbourX, neighbourY] == CellState.Alive)
                {
                    aliveNeighbours++;
                }
            };

            FillWithNoise(startNoise);
        }
Esempio n. 3
0
        public LifeGrid(int height, int width)
        {
            gridHeight = height;
            gridWidth  = width;

            CurrentState = new CellState[gridHeight, gridWidth];
            nextState    = new CellState[gridHeight, gridWidth];
        }
 public GameOfLife(CellState[,] current)
 {
     _current = current;
     GridSize = new GridSize()
     {
         X = current.GetLength(0), Y = current.GetLength(1)
     };
 }
Esempio n. 5
0
    public void InitWithSchem(string wirename)
    {
        state           = InitializeWires(height, width);
        allowCursorDraw = true;
        sources         = new List <source>();

        loadSchematicsFromASCII(wirename);
    }
Esempio n. 6
0
 private LifeGrid(int columns, int rows, CellState[,] initalGrid)
 {
     Grid          = initalGrid;
     SeedStateGrid = initalGrid;
     Columns       = columns;
     Rows          = rows;
     Generation    = 0;
 }
Esempio n. 7
0
 public PuzzleGame()
 {
     _board = new CellState[5, 5];
     for (int i = 0; i <= 4; i += 2)
     {
         _board[i, 1] = _board[i, 3] = Forbidden;
     }
 }
Esempio n. 8
0
    IEnumerator GetBestAction(CellState[,] state, CellState aiPlayer, Action action)
    {
        Score score = new Score();

        yield return(StartCoroutine(RecursiveMinMaxing(state, aiPlayer, action, score)));

        Debug.Log("YOU SHOULD PLAY: " + action.ToString());
    }
Esempio n. 9
0
        private bool CheckIsDead(CellState[,] field, int x, int y)
        {
            var q    = new Queue <PT>();
            var mask = new bool[10, 10];

            q.Enqueue(new PT()
            {
                X = x, Y = y
            });

            while (q.Count > 0)
            {
                var pt = q.Dequeue();

                if (pt.X >= 0 && pt.Y >= 0 && pt.X < 10 && pt.Y < 10)
                {
                    if (!mask[pt.X, pt.Y])
                    {
                        mask[pt.X, pt.Y] = true;

                        switch (field[pt.X, pt.Y])
                        {
                        case CellState.Alive:
                            return(false);

                        case CellState.Free:
                        case CellState.FreeFired:
                            continue;

                        case CellState.Dead:
                        {
                            q.Enqueue(new PT()
                                {
                                    X = pt.X - 1, Y = pt.Y
                                });
                            q.Enqueue(new PT()
                                {
                                    X = pt.X + 1, Y = pt.Y
                                });
                            q.Enqueue(new PT()
                                {
                                    X = pt.X, Y = pt.Y - 1
                                });
                            q.Enqueue(new PT()
                                {
                                    X = pt.X, Y = pt.Y + 1
                                });
                        } break;

                        default:
                            throw new NotImplementedException("");
                        }
                    }
                }
            }

            return(true);
        }
 private static void CheckAndAddBottomRadial(CellState[,] grid, List <Point> radialPoints, int x, int y)
 {
     if (y < grid.GetLength(1) - 1)
     {
         radialPoints.Add(new Point {
             X = x, Y = y + 1
         });
     }
 }
Esempio n. 11
0
        public Universe(ushort dimension)
        {
            Dimension = dimension;

            CurrentState = new CellState[Width, Height];
            NextState    = new CellState[Width, Height];
            Age          = 0;
            Population   = 0;
            Vary         = 0;
        }
Esempio n. 12
0
        public FillWords(IDrawer drawer, int fieldWidth, int fieldHeight)
        {
            _drawer = drawer;

            _fieldWidth  = fieldWidth;
            _fieldHeight = fieldHeight;

            _field      = new Field(fieldWidth, fieldHeight);
            _cellStates = new CellState[_field.GetFieldWidth(), _field.GetFieldHeight()];
        }
Esempio n. 13
0
 public static void Initialize(int width = 100, int height = 100)
 {
     w            = width;
     h            = height;
     grid         = new CellState[h, w];
     gridCopy     = new CellState[h, w];
     initialState = new CellState[h, w];
     temps        = new int[h, w];
     CurrentType  = AutomatonType.Conway;
 }
Esempio n. 14
0
        public GameField(GameController controller)
        {
            _controller = controller;

            RowCount = 15;
            ColCount = 25;

            _field      = new CellColor[RowCount, ColCount];
            _stateField = new CellState[RowCount, ColCount];
        }
        public static CellState[,] SaveCellState(CellState[,] gameState, string filename = FileName)
        {
            using (var writer = System.IO.File.CreateText(FileName))
            {
                var jsonString = JsonSerializer.Serialize(gameState);
                writer.Write(jsonString);

                return(gameState);
            }
        }
Esempio n. 16
0
        public Form1()
        {
            InitializeComponent();
            ClientSize = new Size(nRows * cellSize, nColumns * cellSize);

            FormBorderStyle = FormBorderStyle.FixedSingle;

            KeyUp += KeyCallback;

            cellStates = new CellState[nRows, nColumns];

            grid             = new TableLayoutPanel();
            grid.RowCount    = nRows;
            grid.ColumnCount = nColumns;

            grid.BackColor = Color.Black;

            grid.Size = Size;

            Controls.Add(grid);

            for (int i = 0; i < nRows; ++i)
            {
                for (int j = 0; j < nColumns; ++j)
                {
                    cellStates[i, j] = CellState.BACKGROUND;

                    Button button = new Button();
                    button.BackColor = Color.White;
                    button.KeyDown  += KeyCallback;
                    button.Text      = (i * nColumns + j).ToString();

                    button.Width     = cellSize;
                    button.Height    = cellSize;
                    button.Margin    = Padding.Empty;
                    button.Padding   = Padding.Empty;
                    button.FlatStyle = FlatStyle.Flat;
                    button.FlatAppearance.BorderSize = 1;
                    button.MouseDown += ButtonClick;
                    button.Tag        = i * nColumns + j;

                    TableLayoutPanelCellPosition cellPos = new TableLayoutPanelCellPosition(j, i);
                    grid.SetCellPosition(button, cellPos);

                    grid.Controls.Add(button);
                }
            }

            int nCells = nRows * nColumns;

            for (int i = 0; i < nCells; ++i)
            {
                Q[i] = new double[nCells];
            }
        }
Esempio n. 17
0
 private void AssertCellMatch(CellState[,] cells)
 {
     for (int i = 0; i < cells.GetLength(0); i++)
     {
         for (int j = 0; j < cells.GetLength(1); j++)
         {
             var expectedCell = cells[i, j];
             AssertExpectedCell(expectedCell);
         }
     }
 }
Esempio n. 18
0
 public void CreateDirMatrix()
 {
     dirMatrix = new CellState[width * 2 + 1, height * 2 + 1];
     for (var x = 0; x < width * 2 + 1; x++)
     {
         for (var y = 0; y < height * 2 + 1; y++)
         {
             dirMatrix[x, y] = this[x, y];
         }
     }
 }
Esempio n. 19
0
 private void ChangeButton(CellState[,] map)
 {
     if (playerType == PlayerType.Human)
     {
         FillMe(map);
     }
     else
     {
         MakeMasked(map);
     }
 }
        public static int CountEnemies(this CellState[,] currentBoard, Team team)
        {
            var stats = currentBoard.GetBoardStats();

            if (team == Team.Black)
            {
                return(stats.WhiteKings + stats.WhitePieces);
            }

            return(stats.BlackPieces + stats.BlackKings);
        }
        public CellularAutomaton(int width, int height, Ruleset ruleset, float startNoise, bool aliveBorders)
        {
            this.width        = width;
            this.height       = height;
            this.ruleset      = ruleset;
            this.aliveBorders = aliveBorders;
            cells             = new CellState[width, height];
            copy = new CellState[width, height];

            FillWithNoise(startNoise);
        }
        public static CellState[,] LoadCellState(string fileName = FileName)
        {
            if (System.IO.File.Exists(fileName))
            {
                var jsonString = System.IO.File.ReadAllText(fileName);
                CellState[,] res = JsonSerializer.Deserialize <CellState[, ]>(jsonString);
                return(res);
            }

            return(new CellState[, ]);
        }
Esempio n. 23
0
 private void CopyArray(CellState[,] sourceArray, CellState[,] destinationArray)
 {
     for (int x = 0; x < FieldWidth; x++)
     {
         for (int y = 0; y < FieldHeight; y++)
         {
             destinationArray[x, y] =
                 new CellState(sourceArray[x, y].BallColor, cellSize, sourceArray[x, y].HasBall);
         }
     }
 }
Esempio n. 24
0
 public Battleships()
 {
     Player_1       = "Player_1";
     Player_2       = "Player_2";
     BoardSize      = 1;
     Touch          = 0;
     personalBoard1 = new ShipCell[BoardSize, BoardSize];
     battleBoard1   = new CellState[BoardSize, BoardSize];
     personalBoard2 = new ShipCell[BoardSize, BoardSize];
     battleBoard2   = new CellState[BoardSize, BoardSize];
 }
Esempio n. 25
0
    void Start()
    {
        arrayOfBlocks = new CellState[_gridWidth, _gridHeight];

        for (int i = 0; i < _gridWidth; i++)
        {
            for (int j = 0; j < _gridHeight; j++)
            {
                arrayOfBlocks[i, j] = CellState.None;
            }
        }
    }
Esempio n. 26
0
    public Board()
    {
        Matrix = new CellState[SIZE, SIZE];

        for (int x = 0; x < SIZE; x++) {
            for (int y = 0; y < SIZE; y++) {
                //var position = new Vector3(x - (SIZE / 2), y - (SIZE / 2), 0);
                var position = new Vector3(x*SCALE - (SIZE / 2)*SCALE,y*SCALE- (SIZE / 2)*SCALE,0);
                Matrix[x, y] = CellFactory.Create(position, Random.Range(1, 3) == 1);
            }
        }
    }
Esempio n. 27
0
 public Game(GameSettings settings)
 {
     field           = new CellState[settings.Rows, settings.Columns];
     previousField   = new CellState[settings.Rows, settings.Columns];
     aliveNeighbours = new int[settings.Rows, settings.Columns];
     Rows            = settings.Rows;
     Columns         = settings.Columns;
     this.Reset(CellState.Dead);
     this.stayAliveCount = settings.StayAliveCount;
     this.birthCount     = settings.BirthCount;
     this.isInfinite     = settings.IsInfinite;
 }
Esempio n. 28
0
        public void Render(CellState[,] grid, ControlCommand currentComand)
        {
            const string header = "CONWAYS GAME OF LIFE";
            var          status = currentComand.ToString();
            const string footer = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

            Console.Clear();
            Console.WriteLine(String.Format("{0," + ((Console.WindowWidth / 2) + (header.Length / 2)) + "}", header));
            Console.WriteLine(String.Format("{0," + ((Console.WindowWidth / 2) + (status.Length / 2)) + "}", status));
            Console.WriteLine(GridAsString(grid));
            Console.WriteLine(String.Format("{0," + ((Console.WindowWidth / 2) + (footer.Length / 2)) + "}", footer));
        }
Esempio n. 29
0
        /// <summary>
        /// it should be wrapped in try/catch
        /// </summary>
        public Cross(TextReader t)
        {
            // header
            Name = t.ReadLine()?.Trim();
            if (string.IsNullOrWhiteSpace(Name))
                throw new FormatException("First line have to contains name");
            var s = t.ReadLine();
            if (string.IsNullOrWhiteSpace(s))
                throw new FormatException("Second line must contain 2 spase-separated value: width and height");
            var ss = s.Split((char[]) null, StringSplitOptions.RemoveEmptyEntries);
            if (ss.Length != 2)
                throw new FormatException("Second line must contain 2 spase-separated value: width and height");
            int width = int.Parse(ss[0]);
            int height = int.Parse(ss[1]);
            Top = new Line[width];
            Left = new Line[height];
            map = new CellState[width, height];

            // top block
            if (!string.IsNullOrWhiteSpace(t.ReadLine()))
                throw new FormatException("Line 3 is not empty");
            for (int i = 0; i < width; i++)
            {
                Top[i] = ImportLine(t);
            }

            // left block
            if (!string.IsNullOrWhiteSpace(t.ReadLine()))
                throw new FormatException($"Line {width + 4} is not empty");
            for (int i = 0; i < height; i++)
            {
                Left[i] = ImportLine(t);
            }

            // map (if exists)
            var mapFlag = t.ReadLine();
            if (mapFlag == null)
                return;
            if (!string.IsNullOrWhiteSpace(mapFlag))
                throw new FormatException($"Line {width + height + 5} is not empty");
            for (int i = 0; i < height; i++)
            {
                var mapLine = t.ReadLine();
                if (string.IsNullOrWhiteSpace(mapLine) || mapLine.Length != width)
                    throw new FormatException($"Line {width + height + 6 + i} must contains map line");
                for (int j = 0; j < width; j++)
                {
                    if (!"012".Contains(mapLine[j]))
                        throw new FormatException($"Line {width + height + 6 + i} map containing wrong symbol");
                    map[j, i] = (CellState) (byte) (mapLine[j] - '0');
                }
            }
        }
Esempio n. 30
0
        public void DrawScreen(CellState[,] gameState, int height, int width)
        {
            StringBuilder borders   = new StringBuilder("", height * width); //builds the 2d array takes in the method creating the bounds and the floor and the ceiling and the platform.
            char          character = Convert.ToChar(32);

            for (int y = 0; y < 62; y++)
            {
                character = NewMethod(gameState, height, width, borders, character, y);
            }
            Console.SetCursorPosition(0, 0);
            Console.Write(borders);
        }
Esempio n. 31
0
        protected virtual void UpdateCellsCollection(CellState[,] cellStates)
        {
            for (int x = 0; x < GameSettings.CELL_COUNT_X; x++)
            {
                for (int y = 0; y < GameSettings.CELL_COUNT_Y; y++)
                {
                    var index = GameSettings.CELL_COUNT_X * x + y;

                    Cells[index].State = cellStates[x, y];
                }
            }
        }
Esempio n. 32
0
 public void UpdateState()
 {
     for (int i = 0; i < this.gridHeight; i++)
     {
         for (int j = 0; j < this.gridWidth; j++)
         {
             var liveNeighbors = GetLiveNeighbors(i, j);
             nextState[i, j] = LifeRules.GetNewState(currentState[i, j], liveNeighbors);
         }
     }
     currentState = nextState;
     nextState    = new CellState[this.gridHeight, this.gridWidth];
 }
Esempio n. 33
0
        void Step()
        {
            state = new CellState[height, width];
            int PlayerX = player.getX();
            int PlayerY = player.getY();

            state[PlayerY, PlayerX] = CellState.Impaler;
            int Player2X = player2.getX();
            int Player2Y = player2.getY();

            state[Player2Y, Player2X] = CellState.Enemy;
            CheckCollision();
        }
Esempio n. 34
0
        private static CellState[,] CloneMatrix(CellState[,] oldMatrix)
        {
            CellState[, ]? newMatrix = new CellState[oldMatrix.GetLength(0), oldMatrix.GetLength(1)];
            for (int y = 0; y < oldMatrix.GetLength(1); y++)
            {
                for (int x = 0; x < oldMatrix.GetLength(0); x++)
                {
                    newMatrix[x, y] = oldMatrix[x, y];
                }
            }

            return(newMatrix);
        }
Esempio n. 35
0
 public Cross(int width, int height)
 {
     Name = $@"{width} x {height}";
     Top = new Line[width];
     Left = new Line[height];
     for (int i = 0; i < width; i++)
         Top[i] = new Line();
     for (int i = 0; i < height; i++)
         Left[i] = new Line();
     map = new CellState[width, height];
     for (int i = 0; i < width; i++)
         for (int j = 0; j < height; j++)
             map[i, j] = CellState.Dot;
 }
Esempio n. 36
0
 public Board2(CellState[,] cells)
 {
     _cells = cells;
 }
	// Used to reset the pathfinding when the level is regenerated
	public static void ResetPathfinding()
	{		
		gridWidth = LevelGen.CellGrid.Width;
		gridHeight = LevelGen.CellGrid.Height;
		
		// Allocate grids
		cellStates = new CellState[gridWidth, gridHeight];
		pathFindingGrid = new GridCell[gridWidth, gridHeight];
		
		// Initialise state grid
		for (int x = 0; x < gridWidth; ++x)
			for (int y = 0; y < gridHeight; ++y)
		{
			cellStates[x, y] = CellState.UNKNOWN;
		}
		
		// Initialise pathfinding grid
		for (int x = 0; x < gridWidth; ++x)
			for (int y = 0; y < gridHeight; ++y)
		{
			pathFindingGrid[x, y] = new GridCell(x, y, false);
		}
		
		cellGrid = new CellGrid(pathFindingGrid, LevelGen.Instance.transform, LevelGen.MAZE_RESOLUTION);
		
		currentTargets.Clear();
	}
Esempio n. 38
0
        public Sim(SimConfig config, Rules rules)
        {
            Cells = new CellState[config.Width, config.Height];
            CellsLastChange = new int[config.Width, config.Height];

            Rules = rules;
            Agents = new List<Agent>();

            for (var agentX = 1; agentX < config.Width; agentX += 2)
            {
                for (var agentY = 1; agentY < config.Height; agentY += 2)
                {
                    var agent = new Agent
                    {
                        Sim = this,
                        Location = new Point(agentX, agentY),
                        Goal = rules.Goal,
                        CellVisitOrder = rules.CellVisitOrder,
                    };
                    Agents.Add(agent);

                    Cells[agentX, agentY] = CellState.Agent;
                }
            }
        }
Esempio n. 39
0
 public void Clear()
 {
     this.stones = new CellState[size, size];
 }
Esempio n. 40
0
 public static void Initialize(int width = 100, int height = 100)
 {
     w = width;
     h = height;
     grid = new CellState[h, w];
     gridCopy = new CellState[h, w];
     initialState = new CellState[h, w];
     temps = new int[h, w];
     CurrentType = AutomatonType.Conway;
 }
Esempio n. 41
0
        public Board2(int width, int height)
        {
            _cells = new CellState[width, height];

            InitializeBoard();
        }
Esempio n. 42
0
 public BoardModel(int sz)
 {
     d_size = sz;
     d_board = new CellState[sz, sz];
     BoardModelUtil.ClearBoard( this );
 }
Esempio n. 43
0
 void reallocate()
 {
     m_aCells = new CellState[m_ncx, m_ncy];
     for (uint i=0; i<m_ncx; i++)
         for (uint j=0; j<m_ncy; j++)
             m_aCells[i, j] = CellState.eFree;
 }