public Cell(CellStates cellStates, int x, int y)
 {
     // TODO: Complete member initialization
     this.state = cellStates;
     this.x = x;
     this.y = y;
 }
Example #2
0
 public Cell(CellStates cellState, float x, float y, int id)
 {
     this.cellState = cellState;
     this.x         = x;
     this.y         = y;
     this.id        = id;
 }
Example #3
0
        //<Summary>
        //Check neighboring Cell states and then change the states as per rules
        //</Summary>
        public void NewState(Cell prevCell, Cell currentCell, Cell nextCell)
        {
            CellStates prevState = prevCell.state;           //state of previous cell
            CellStates nextState = nextCell.state;           //state of next cell
            CellStates current   = currentCell.state;        //state of current cell

            CellStates previous = currentCell.PreviousState; //Previous state of current cellstate
            CellStates next     = currentCell.NextState;     //Next state of current cellstate

            if (prevState == next && nextState == next)
            {
                state = previous;
            }
            else if (prevState == next || nextState == next)
            {
                state = next;
            }
            else if (prevState == current && nextState == current)
            {
                state = next;
            }
            else
            {
                state = current;
            }
        }
Example #4
0
    void PieceInit(int type, int rotate, Color color, int x, int y)
    {
        CellStates[,] matrix = new CellStates[5, 5];

        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                matrix[i, j] = CellStates.EMPTY;
            }
        }

        piece = new Piece(matrix, type, color, x, y);


        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                piece.matrixPiece[i, j] = (CellStates)Const.mPieces[type, rotate, i, j];
            }
        }

        piece.pieceType = type;
    }
Example #5
0
        public static CellStates GetDeadState(CellStates state)
        {
            switch (state)
            {
            case CellStates.SmallShip:
                return(CellStates.DeadSmallShip);

            case CellStates.ShipBackUp:
                return(CellStates.ShipBackUpDead);

            case CellStates.ShipBackRight:
                return(CellStates.ShipBackRightDead);

            case CellStates.ShipHeadUp:
                return(CellStates.ShipHeadUpDead);

            case CellStates.ShipHeadRight:
                return(CellStates.ShipHeadRightDead);

            case CellStates.ShipMiddleUp:
                return(CellStates.ShipMiddleUpDead);

            case CellStates.ShipMiddleRight:
                return(CellStates.ShipMiddleRightDead);

            default:
                throw new ArgumentException();
            }
        }
Example #6
0
        private void SetCellColorByMode(Vertex2D pos)
        {
            CellStates cellMode = GetSelectedCellStateMode();

            UpdateStartOrTargetByMode(pos, cellMode);
            gridMaze.SetCellColorAtPosition(pos, GetCellColorByMode(cellMode));
        }
Example #7
0
        public CellRow(int seed)
        {
            cellLine = new Cell[TOTALCELLS];
            newLine  = new Cell[TOTALCELLS];

            //Set up random object and initialise with given seed value
            Random random = new Random(seed);

            int randomNumber;

            for (int i = 0; i < TOTALCELLS; i++)
            {
                //Generate a random number of  0 to 3
                randomNumber = random.Next((int)(CellStates.THREE) + 1);
                //Based on random number, generate corresponding cell states
                CellStates state = Cell.CurrentState(randomNumber);
                //<summary>
                //Create (TOTALCELLLS) instances of of Cell class with
                //constructor parameter and put them in array
                //Resulting Array - cellLine[x].state = CellStates.(state)
                //cellLine for storing automa and newLine for building new generation
                //</Summary>
                cellLine[i] = new Cell(state);
                newLine[i]  = new Cell(state);
            }
        }
Example #8
0
 private void CheckTheEnd(CellStates s)
 {
     if (s == CellStates.OPEN_BOMB || CountOpenCells == NumCols * NumRows - NumBombs)
     {
         TheEnd = true;
     }
 }
Example #9
0
        private int CalculateSouthEastValue(int row, int column, CellStates player, CellStates opponent)
        {
            int originOffset = Math.Min(row, column);
            int endOffset    = Math.Min(_game.Columns - 1 - column, _game.Rows - 1 - row);

            if ((originOffset + endOffset + 1) < _game.PiecesToWin)
            {
                return(0);
            }

            int  ownedPieces = 0;
            int  lostPieces  = 0;
            bool blocked     = false;

            int r = row - originOffset;

            for (int c = column - originOffset; c <= (column + endOffset);)
            {
                CellStates cellState = CellStates.Empty;
                switch (_game.Board[r++, c++])
                {
                case Players.Black:
                    cellState = CellStates.Black;
                    break;

                case Players.Red:
                    cellState = CellStates.Red;
                    break;
                }

                if (cellState == opponent)
                {
                    // this iteration should add 0 value
                    lostPieces++;
                    blocked = true;
                }
                else if (cellState == player)
                {
                    ownedPieces++;
                }
                else
                {
                    // do nothing if this is a blank cell
                }
            }

            if (!blocked)
            {
                return(2 ^ ownedPieces);
            }
            else if (lostPieces == (_game.PiecesToWin - 1) && ownedPieces == 1)
            {
                // if this is a true block, make its value fall midway between a win, and 1 away from a win
                return(2 ^ (_game.PiecesToWin - 1) + (2 ^ _game.PiecesToWin - 2));
            }

            return(0);
        }
Example #10
0
        public static Bitmap GetResource(CellStates state)
        {
            switch (state)
            {
            case CellStates.Water:
                return(Resource1.Water);

            case CellStates.SmallShip:
                return(Resource1.SmallShip);

            case CellStates.DeadSmallShip:
                return(Resource1.SmallShipDead);

            case CellStates.Empty:
                return(Resource1.Miss);

            case CellStates.ShipHeadUp:
                return(Resource1.ship_head);

            case CellStates.ShipHeadUpDead:
                return(Resource1.ship_head_dead);

            case CellStates.ShipHeadRight:
                return(Resource1.ship_head_r);

            case CellStates.ShipHeadRightDead:
                return(Resource1.ship_head_dead_r);

            case CellStates.ShipMiddleUp:
                return(Resource1.ship_middle);

            case CellStates.ShipMiddleUpDead:
                return(Resource1.ship_middle_dead);

            case CellStates.ShipMiddleRight:
                return(Resource1.ship_middle_r);

            case CellStates.ShipMiddleRightDead:
                return(Resource1.ship_middle_dead_r);

            case CellStates.ShipBackUp:
                return(Resource1.ship_back);

            case CellStates.ShipBackUpDead:
                return(Resource1.ship_back_dead);

            case CellStates.ShipBackRight:
                return(Resource1.ship_back_r);

            case CellStates.ShipBackRightDead:
                return(Resource1.ship_back_dead_r);

            default:
                throw new ArgumentException();
            }
        }
Example #11
0
        public bool IfIsWinner(CellStates player, CellStates[,] grid)
        {
            var _TotalRows    = grid.GetLength(1);
            var _TotalColumns = grid.GetLength(0);

            if (player == 0)
            {
                return(false);
            }

            // horizontalCheck
            for (int j = 0; j < _TotalRows - 3; j++)
            {
                for (int i = 0; i < _TotalColumns; i++)
                {
                    if (grid[i, j] == player && grid[i, j + 1] == player && grid[i, j + 2] == player && grid[i, j + 3] == player)
                    {
                        return(true);
                    }
                }
            }
            // verticalCheck
            for (int i = 0; i < _TotalColumns - 3; i++)
            {
                for (int j = 0; j < _TotalRows; j++)
                {
                    if (grid[i, j] == player && grid[i + 1, j] == player && grid[i + 2, j] == player && grid[i + 3, j] == player)
                    {
                        return(true);
                    }
                }
            }
            // ascendingDiagonalCheck
            for (int i = 3; i < _TotalColumns; i++)
            {
                for (int j = 0; j < _TotalRows - 3; j++)
                {
                    if (grid[i, j] == player && grid[i - 1, j + 1] == player && grid[i - 2, j + 2] == player && grid[i - 3, j + 3] == player)
                    {
                        return(true);
                    }
                }
            }
            // descendingDiagonalCheck
            for (int i = 3; i < _TotalColumns; i++)
            {
                for (int j = 3; j < _TotalRows; j++)
                {
                    if (grid[i, j] == player && grid[i - 1, j - 1] == player && grid[i - 2, j - 2] == player && grid[i - 3, j - 3] == player)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Eto.Forms.CellEventArgs"/> class.
 /// </summary>
 /// <param name="grid">Grid the event is triggered for.</param>
 /// <param name="cell">Cell the event is triggered for.</param>
 /// <param name="row">Row for the cell.</param>
 /// <param name="column">Column for the cell.</param>
 /// <param name="item">Item the cell is displaying.</param>
 /// <param name="cellState">State of the cell.</param>
 /// <param name="control">Control object for the cell (if any)</param>
 public CellEventArgs(Grid grid, Cell cell, int row, int column, object item, CellStates cellState, Control control)
 {
     Grid      = grid;
     Cell      = cell;
     Column    = column;
     Row       = row;
     Item      = item;
     CellState = cellState;
     Control   = control;
 }
Example #13
0
 public void MarkCell()
 {
     if (State == CellStates.CLOSE)
     {
         State = CellStates.MARKED;
     }
     else if (State == CellStates.MARKED)
     {
         State = CellStates.CLOSE;
     }
 }
Example #14
0
    // Use this for initialization
    void Start()
    {
        xoScripts = gameObject.GetComponentsInChildren <XOScript> ();

        if (xoScripts == null)
        {
            Debug.Log("XO Scripts Array is EMPTY");
        }

        state = CellStates.empty;                               // all cells are initially empty.
    }
Example #15
0
        internal Utility CalculateValues(Players player)
        {
            CellStates playerState   = (player == Players.Black) ? CellStates.Black : CellStates.Red;
            CellStates opponentState = (player == Players.Black) ? CellStates.Red : CellStates.Black;

            Utility result = new Utility();

            result.PlayerValue   = CalculatePlayerValues(playerState, opponentState);
            result.OpponentValue = CalculatePlayerValues(opponentState, playerState);

            return(result);
        }
Example #16
0
        private void UpdateStartOrTargetByMode(Vertex2D pos, CellStates cellMode)
        {
            switch (cellMode)
            {
            case CellStates.Start:
                UpdateStartCellColor(pos);
                break;

            case CellStates.Target:
                UpdateTargetCellColor(pos);
                break;
            }
        }
Example #17
0
        public string DrawStringBuilder(int nk)
        {
            var mybuilder = new StringBuilder();

            List <string> mypick = new List <string>();

            foreach (var item in chosingColorRandomly())
            {
                mypick.Add(item);
            }
            foreach (var item in mypick)
            {
                finalpick.Add(item);
            }


            CellStates[,] cells = new CellStates[6, 7];

            var builder = new StringBuilder();
            var header  = "  0        1         2         3        4        5         6";
            var divisor = "-------------------------------------------------------------------";

            builder.AppendLine(header);
            builder.AppendLine(divisor);

            int p = 0;

            for (int i = 0; i < cells.GetLength(0); i++)
            {
                for (int j = 0; j < cells.GetLength(1); j++)
                {
                    int counter1 = 0;
                    int counter2 = 1;
                    cells[5, nk] = CellStates.Player;
                    //cells[5, 0] = CellStates.User;
                    var str = cells[i, j] == CellStates.Empty ? "| ······· " : (cells[i, j] == CellStates.User ? "|     0   " : "|   x     ");

                    builder.Append(str);
                    counter1 = counter1 + 2;
                    counter2++;
                }



                builder.Append('|');
                builder.AppendLine();
                builder.AppendLine(divisor);
            }
            SendingPacket(builder);
            return(builder.ToString(0, builder.Length - 1));
        }
Example #18
0
 /// <summary>
 /// Convert a cellstate (logical) to its static gfx resourceID
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public static ResourceID Convert(CellStates input)
 {
     switch(input)
     {
         case(CellStates.Void) : return ResourceID.StaticTileVoid;
         case (CellStates.Wall): return ResourceID.StaticTileWall;
         case (CellStates.Floor): return ResourceID.StaticTileFloor;
         case (CellStates.FloorCrate): return ResourceID.StaticTileFloorCrate;
         case (CellStates.FloorGoal): return ResourceID.StaticTileFloorGoal;
         case (CellStates.FloorGoalPlayer): return ResourceID.StaticTileFloorGoalPlayer;
         case (CellStates.FloorGoalCrate): return ResourceID.StaticTileFloorGoalCrate;
         case (CellStates.FloorPlayer): return ResourceID.StaticTileFloorPlayer;
     }
     throw new Exception("Unhandled enum");
 }
Example #19
0
 public void Open()
 {
     if (State == CellStates.CLOSE || State == CellStates.MARKED)
     {
         if (IsBomb)
         {
             State = CellStates.OPEN_BOMB;
         }
         else
         {
             Title = BombQuantityAround == 0 ? "" : BombQuantityAround.ToString();
             State = CellStates.OPEN_CLEAR;
         }
     }
 }
Example #20
0
 public static Bitmap GetResource(CellStates state)
 {
     switch (state)
     {
         case CellStates.Water:
             return Resource1.Water;
         case CellStates.Ship:
             return Resource1.ship1;
         case CellStates.DeadShip:
             return Resource1.ship1_dead;
         case CellStates.Empty:
             return Resource1.morj;
         default:
             throw new ArgumentException();
     }
 }        
Example #21
0
        private int CalculateCellValue(int row, int column, CellStates cellState, CellStates player, CellStates opponent)
        {
            // if the cell is owned by the opponent, it has zero value
            if (cellState == opponent)
            {
                return(0);
            }

            int result = 0;

            result += CalculateEastWestValue(row, column, player, opponent);
            result += CalculateSouthEastValue(row, column, player, opponent);
            result += CalculateNorthSouthValue(row, column, player, opponent);
            result += CalculateSouthWestValue(row, column, player, opponent);

            return(result);
        }
Example #22
0
 public void DrawCell(Vector2 position, int type, CellStates state)
 {
     Vector2[] posArr = new Vector2[4];
     posArr[0] = position;
     listOfBuildings[type].Draw(posArr);
     for (int i = 0; i < posArr.Length; i++)
     {
         if (CellStates.ground.Equals(map[(int)posArr[i].x, (int)posArr[i].y].gameObject.GetComponent <HexagonClick>().getCellState()))
         {
             map[(int)posArr[i].x, (int)posArr[i].y].gameObject.GetComponent <HexagonClick>().setCellState(state);
         }
         else
         {
             map[(int)posArr[i].x, (int)posArr[i].y].gameObject.GetComponent <HexagonClick>().setCellState(CellStates.error);
         }
     }
 }
Example #23
0
 public static ShipDirection GetDirection(CellStates cell)
 {
     if (cell == CellStates.Water || cell == CellStates.Empty)
     {
         throw new ArgumentException();
     }
     if (cell == CellStates.SmallShip || cell == CellStates.DeadSmallShip)
     {
         return(ShipDirection.Up);
     }
     if (cell == CellStates.ShipBackRight || cell == CellStates.ShipBackRightDead ||
         cell == CellStates.ShipHeadRight || cell == CellStates.ShipHeadRightDead ||
         cell == CellStates.ShipMiddleRight || cell == CellStates.ShipMiddleRightDead)
     {
         return(ShipDirection.Right);
     }
     else
     {
         return(ShipDirection.Up);
     }
 }
Example #24
0
        private int CalculatePlayerValues(CellStates player, CellStates opponent)
        {
            int result = 0;

            for (int r = 0; r < _game.Rows; r++)
            {
                for (int c = 0; c < _game.Rows; c++)
                {
                    CellStates value = CellStates.Empty;
                    if (_game.Board[r, c] == Players.Black)
                    {
                        value = CellStates.Black;
                    }
                    else if (_game.Board[r, c] == Players.Red)
                    {
                        value = CellStates.Red;
                    }

                    result += CalculateCellValue(r, c, value, player, opponent);
                }
            }

            return(result);
        }
Example #25
0
 private void StateBuilder()
 {
     //Print Corresponding special character of CellStates in the row
     for (int i = 0; i < TOTALCELLS; i++)
     {
         CellStates state = cellLine[i].State;
         if (state == CellStates.ZERO)
         {
             Console.Write(" ");
         }
         else if (state == CellStates.ONE)
         {
             Console.Write(".");
         }
         else if (state == CellStates.TWO)
         {
             Console.Write("+");
         }
         else
         {
             Console.Write("#");
         }
     }
 }
	public void SetStateToCells (List<int> pmCellsList, CellStates pmStatus)
	{
		foreach (int lvField in pmCellsList) {
			CellStatus lvStatus = instance.mCells [lvField].GetComponent<CellStatus> ();
			lvStatus.SetState (pmStatus);
		}
	}
Example #27
0
        /// <summary>
        /// Update the cursor position
        /// </summary>
        /// <param name="X">Mouse X</param>
        /// <param name="Y">Mouse Y</param>
        /// <param name="ClickCount">Number of clicks</param>
        /// <param name="Button">Button enum 0=None, 1=Left, 2=Right</param>
        /// <returns>true is cursor is drawn by game</returns>
        public bool SetCursor(int X, int Y, int ClickCount, GameUI.MouseButtons Button, GameUI.MouseClicks ClickType)
        {
            bool manualDraw = false;

            // Relative position
            int rX = X - GameUI.GameCoords.GlobalOffset.X;
            int rY = Y - GameUI.GameCoords.GlobalOffset.Y;

            // Set the mouse cursor, if it is on the page
            //if (rX >= 0 && rY >= 0)
            {
                this.CurrentLogical = new VectorInt(rX, rY);
            }

            // Find the puzzle cell position
            VectorInt puzPos = GameUI.GameCoords.PuzzleFromPositionAbs(this.CurrentAbsolute);
            CellStates puzCell = CellStates.Void;
            if (GameUI.Current.Rectangle.Contains(puzPos))
            {
                // Is this cursor within the puzzle
                manualDraw = true;
                puzCell = GameUI.Current[puzPos];
            }

            // Click started
            if (ClickCount > 0 && ClickType == GameUI.MouseClicks.Down)
            {
                dragStarted = true;
                dragStartPixelLocation = this.CurrentAbsolute;
                dragStartCellLocation = puzPos;
                dragStartCell = puzCell;
            }

            // Click ended
            if (ClickCount > 0 && ClickType == GameUI.MouseClicks.Up)
            {
                dragStarted = false;
                if (dragStartCell == CellStates.Floor || dragStartCell == CellStates.FloorGoal)
                {
                    PerformPlayerMovement(puzPos, puzCell);
                }
                else if (dragStartCell == CellStates.FloorCrate || dragStartCell == CellStates.FloorGoalCrate)
                {
                    PerformCrateMovement(dragStartCellLocation, puzPos);
                }
            }

            // Let the rest of the world know...
            if (OnClick != null)
            {
                OnClick(this, new NodeCursorEventArgs(this, "Click", this, X, Y, ClickCount, Button, ClickType));
            }

            return manualDraw;
        }
Example #28
0
 private int CalculateSouthWestValue(int row, int column, CellStates player, CellStates opponent)
 {
     return 0;
 }
Example #29
0
 DrawableCellStates(CellStates value)
 {
     this.value = value;
 }
Example #30
0
 /// <summary>
 /// Convert logic cell's to combination cell states
 /// </summary>
 /// <param name="cell"></param>
 /// <returns></returns>
 public static Cell Convert(CellStates cell)
 {
     switch (cell)
     {
         case (CellStates.Void): return Cell.Void;
         case (CellStates.Wall): return Cell.Wall;
         case (CellStates.Floor): return Cell.Floor;
         case (CellStates.FloorPlayer): return Cell.Player;
         case (CellStates.FloorGoal): return Cell.Goal;
         case (CellStates.FloorGoalCrate): return Cell.Goal;
         case (CellStates.FloorCrate): return Cell.Crate;
         case (CellStates.FloorGoalPlayer): return Cell.Player;
     }
     throw new InvalidOperationException();
 }
	public void SetState(CellStates state)
	{
		switch (state) {
			case CellStates.DISABLED:
				this.avaiable = false;
				break;
			case CellStates.ENABLED:
				this.avaiable = true;
				break;
			case CellStates.TARGET:
				this.target = true;
				break;
			case CellStates.OPPORTUNITY:
				this.lvOportunity = true;
				break;
			case CellStates.MOVABLE:
				this.movable = true;
				break;
			case CellStates.CLOSE_RANGE:
				this.closeRange = true;
				break;
			case CellStates.FAR_RANGE:
				this.farRange = true;
				break;	
			default:
				this.avaiable = true;
				break;
		}
	}
 public Board(int x, int y)
 {
     CreateNewBoard(x, y);
     movesPerformed = 0;
     winner = CellStates.Empty;
 }
Example #33
0
        /// <summary>
        /// Generate a bitmap for a particular cell state
        /// </summary>
        /// <param name="cell">Search for</param>
        /// <returns></returns>
        public Bitmap ToBitmap(CellStates cell)
        {
            SizeInt size = Size;

            Bitmap result = new Bitmap(size);
            for (int cx = 0; cx < size.X; cx++)
                for (int cy = 0; cy < size.Y; cy++)
                {
                    if (this[cx, cy] == cell) result[cx, cy] = true;
                }

            return result;
        }
Example #34
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Eto.Forms.DrawableCellPaintEventArgs"/> class.
		/// </summary>
		/// <param name="graphics">Graphics context for drawing.</param>
		/// <param name="clipRectangle">Clip rectangle for the cell's region.</param>
		/// <param name="cellState">State of the cell.</param>
		/// <param name="item">Item from the data store for the row that is being painted.</param>
		public CellPaintEventArgs(Graphics graphics, RectangleF clipRectangle, CellStates cellState, object item)
			: base(graphics, clipRectangle)
		{
			CellState = cellState;
			Item = item;
		}
Example #35
0
 public Cell(CellStates cellState, float x, float y)
 {
     this.cellState = cellState;
     this.x         = x;
     this.y         = y;
 }
 protected override bool CheckForMatch(CellStates player, params Vector2[] coordinates)
 {
     int matches = 0;
     foreach (Vector2 v in coordinates)
     {
         //retrieve the correct cell
         Board currentCell = board[(int)v.x, (int)v.y];
         //get its current value
         CellStates displayedValue = currentCell.Winner;
         //compare to confirm match
         //p1 == x, p2 == y
         if (player == displayedValue) //Player will be either p1 or p2, and can check against the winner field directly
         {
             matches++;
         }
     }
     return matches == coordinates.Length;
 }
Example #37
0
        //<Summary>
        //Check neighboring Cell states and then change the states as per rules
        //</Summary>
        public void NewState(Cell prevCell, Cell currentCell, Cell nextCell)
        {
            CellStates prevState = prevCell.state; //state of previous cell
            CellStates nextState = nextCell.state; //state of next cell
            CellStates current = currentCell.state; //state of current cell

            CellStates previous = currentCell.PreviousState; //Previous state of current cellstate
            CellStates next = currentCell.NextState; //Next state of current cellstate

            if (prevState == next && nextState == next)
            {
                state = previous;
            }
            else if (prevState == next || nextState == next)
            {
                state = next;
            }
            else if (prevState == current && nextState == current)
            {
                state = next;
            }
            else
                state = current;
        }
Example #38
0
 //Constructor that populate the property
 public Cell(CellStates setState)
 {
     state = setState;
 }
Example #39
0
        private int CalculateCellValue(int row, int column, CellStates cellState, CellStates player, CellStates opponent)
        {
            // if the cell is owned by the opponent, it has zero value
            if (cellState == opponent)
                return 0;

            int result = 0;
            result += CalculateEastWestValue(row, column, player, opponent);
            result += CalculateSouthEastValue(row, column, player, opponent);
            result += CalculateNorthSouthValue(row, column, player, opponent);
            result += CalculateSouthWestValue(row, column, player, opponent);

            return result;
        }
Example #40
0
        private int CalculatePlayerValues(CellStates player, CellStates opponent)
        {
            int result = 0;

            for (int r = 0; r < _game.Rows; r++)
            {
                for (int c = 0; c < _game.Rows; c++)
                {
                    CellStates value = CellStates.Empty;
                    if(_game.Board[r, c] == Players.Black)
                        value = CellStates.Black;
                    else if(_game.Board[r, c] == Players.Red)
                        value = CellStates.Red;

                    result += CalculateCellValue(r, c, value, player, opponent);
                }
            }

            return result;
        }
 public Board()
 {
     movesPerformed = 0;
     winner = CellStates.Empty;
 }
Example #42
0
 /// <summary>
 /// Fill a box, not the insides with a CellState
 /// </summary>
 /// <param name="R"></param>
 /// <param name="C"></param>
 public void FillBox(RectangleInt R, CellStates C)
 {
     for (int px = R.TopLeft.X; px <= R.BottomRight.X; px++)
         for (int py = R.TopLeft.Y; py <= R.BottomRight.Y; py++)
         {
             if (px == R.TopLeft.X || py == R.TopLeft.Y || px == R.BottomRight.X || py == R.BottomRight.Y)
             {
                 this[new VectorInt(px, py)] = C;
             }
         }
 }
 public virtual void CheckForWin()
 {
     bool foundWin = false;
     //check all 8 ways a win can happen, for each player
     for(int i = 1; i <= 2; i++)
     {
         //There are a lot of goto's in this method.
         //Since checking is fairly expensive, once we find a single match, others won't change anything
         //The gotos spare the computer this unnecessary expense
         CellStates desiredPlayer = (i == 1 ? CellStates.P1 : CellStates.P2);
         //rows
         if(CheckCoordinates(0, 0, 0, 1, 0, 2, desiredPlayer))
         {
             foundWin = true;
             goto EndOfWinChecks;
         }
         if (CheckCoordinates(1, 0, 1, 1, 1, 2, desiredPlayer))
         {
             foundWin = true;
             goto EndOfWinChecks;
         }
         if (CheckCoordinates(2, 0, 2, 1, 2, 2, desiredPlayer))
         {
             foundWin = true;
             goto EndOfWinChecks;
         }
         //columns
         if (CheckCoordinates(0, 0, 1, 0, 2, 0, desiredPlayer))
         {
             foundWin = true;
             goto EndOfWinChecks;
         }
         if (CheckCoordinates(0, 1, 1, 1, 2, 1, desiredPlayer))
         {
             foundWin = true;
             goto EndOfWinChecks;
         }
         if (CheckCoordinates(0, 2, 1, 2, 2, 2, desiredPlayer))
         {
             foundWin = true;
             goto EndOfWinChecks;
         }
         //diagonals
         if (CheckCoordinates(0, 0, 1, 1, 2, 2, desiredPlayer))
         {
             foundWin = true;
             goto EndOfWinChecks;
         }
         if (CheckCoordinates(2, 0, 1, 1, 0, 2, desiredPlayer))
         {
             foundWin = true;
             goto EndOfWinChecks;
         }
     EndOfWinChecks:
         if(foundWin)
         {
             winner = (i == 1 ? CellStates.P1 : CellStates.P2);
             DisableBoard();
             return;
         }
     }
     if (winner == CellStates.Empty && ThisBoardIsFull())
     {
         GameObject.Find("Controller Scripts").GetComponent<InputManager>().SetContestedBoard(this);
     }
 }
Example #44
0
 /// <summary>
 /// Fill the entire puzzle with <paramref name="C"/>
 /// </summary>
 /// <param name="C"></param>
 public void Fill(CellStates C)
 {
     Fill(Rectangle, C);
 }
Example #45
0
 /// <summary>
 /// Get a state image
 /// </summary>
 /// <param name="cellState"></param>
 /// <returns></returns>
 public Image GetImage(CellStates cellState)
 {
     return  tiles[(int) cellState];
 }
Example #46
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Eto.Forms.DrawableCellPaintEventArgs"/> class.
 /// </summary>
 /// <param name="graphics">Graphics.</param>
 /// <param name="clipRectangle">Clip rectangle.</param>
 /// <param name="cellState">Cell state.</param>
 /// <param name="item">Item.</param>
 public DrawableCellPaintEventArgs(Graphics graphics, RectangleF clipRectangle, CellStates cellState, object item)
     : base(graphics, clipRectangle, cellState, item)
 {
 }
Example #47
0
 public WpfCellEventArgs(Grid grid, CustomCell cell, int row, swc.DataGridColumn column, object item, CellStates cellState, Control control = null)
     : base(grid, cell, row, -1, item, cellState, control)
 {
     _gridColumn = column;
 }
Example #48
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Eto.Forms.DrawableCellPaintEventArgs"/> class.
		/// </summary>
		/// <param name="graphics">Graphics.</param>
		/// <param name="clipRectangle">Clip rectangle.</param>
		/// <param name="cellState">Cell state.</param>
		/// <param name="item">Item.</param>
		public DrawableCellPaintEventArgs(Graphics graphics, RectangleF clipRectangle, CellStates cellState, object item)
			: base(graphics, clipRectangle, cellState, item)
		{
		}
Example #49
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Eto.Forms.DrawableCellPaintEventArgs"/> class.
 /// </summary>
 /// <param name="graphics">Graphics context for drawing.</param>
 /// <param name="clipRectangle">Clip rectangle for the cell's region.</param>
 /// <param name="cellState">State of the cell.</param>
 /// <param name="item">Item from the data store for the row that is being painted.</param>
 public CellPaintEventArgs(Graphics graphics, RectangleF clipRectangle, CellStates cellState, object item)
     : base(graphics, clipRectangle)
 {
     CellState = cellState;
     Item      = item;
 }
Example #50
0
        private int CalculateSouthEastValue(int row, int column, CellStates player, CellStates opponent)
        {
            int originOffset = Math.Min(row, column);
            int endOffset = Math.Min(_game.Columns - 1 - column, _game.Rows - 1 - row);

            if ((originOffset + endOffset + 1) < _game.PiecesToWin) return 0;

            int ownedPieces = 0;
            int lostPieces = 0;
            bool blocked = false;

            int r  = row - originOffset;
            for(int c = column - originOffset; c <= (column + endOffset);)
            {
                CellStates cellState = CellStates.Empty;
                switch (_game.Board[r++, c++])
                {
                    case Players.Black:
                        cellState = CellStates.Black;
                        break;
                    case Players.Red:
                        cellState = CellStates.Red;
                        break;
                }

                if (cellState == opponent)
                {
                    // this iteration should add 0 value
                    lostPieces++;
                    blocked = true;
                }
                else if (cellState == player)
                {
                    ownedPieces++;
                }
                else
                {
                    // do nothing if this is a blank cell
                }

            }

            if (!blocked)
            {
                return 2 ^ ownedPieces;
            }
            else if (lostPieces == (_game.PiecesToWin - 1) && ownedPieces == 1)
            {
                // if this is a true block, make its value fall midway between a win, and 1 away from a win
                return (2 ^ (_game.PiecesToWin - 1) + (2 ^ _game.PiecesToWin - 2));
            }

            return 0;
        }
Example #51
0
 /// <summary>
 /// Count the number of cellstate found in the entire puzzle
 /// </summary>
 /// <param name="cs"></param>
 /// <returns></returns>
 public int Count(CellStates cs)
 {
     int c = 0;
     for (int x=0; x<Size.X; x++)
         for (int y = 0; y < Size.Y; y++)
         {
             if (this[x, y] == cs) c++;
         }
     return c;
 }
Example #52
0
		public MutableCellEventArgs(int row, object item, CellStates cellState)
			: base(row, item, cellState)
		{
		}
Example #53
0
 private Color GetCellColorByMode(CellStates state)
 {
     return(stateModeColorMap[state]);
 }
 //it is easier for the caller to pass in 6, but easier for the function to process 3
 //use this to make them meet in the middle
 protected bool CheckCoordinates(int aa, int ab, int ba, int bb, int ca, int cb, CellStates player)
 {
     Vector2 a = new Vector2(aa, ab);
     Vector2 b = new Vector2(ba, bb);
     Vector2 c = new Vector2(ca, cb);
     return CheckForMatch(player, a, b, c);
 }
Example #55
0
        /// <summary>
        /// Move the player
        /// </summary>
        /// <param name="puzPos"></param>
        /// <param name="puzCell"></param>
        private void PerformPlayerMovement(VectorInt puzPos, CellStates puzCell)
        {
            // Do not allow the move, it other previous moves are still pending
            if (puzCell != CellStates.Void && !GameUI.Player.HasFutureMoves)
            {
                // Draw the path from the player to the this as a path
                VectorInt playerPos = GameUI.Current.Player;

                // Try Path movement
                List<Direction> path = Convert(MoveAnalysis.FindPlayerPath(GameUI.Current, puzPos));
                if (path != null)
                {
                    foreach (Direction aMove in path)
                    {
                        GameUI.Player.doMove(aMove);
                    }
                }
            }
        }
 //check if all coordinates passed in match
 protected virtual bool CheckForMatch(CellStates player, params Vector2[] coordinates)
 {
     int matches = 0;
     for (int i = 0; i < coordinates.Length; i++ )
     {
         Vector2 v = coordinates[i];
         //retrieve the correct cell
         GameObject currentCell = cells[(int)v.x, (int)v.y];
         CellStatus cellStatus = currentCell.GetComponent<CellStatus>();
         if (cellStatus == null)
         {
             Debug.LogError("Cell missing its CellStatus component");
         }
         //get its current value
         CellStatus.Piece displayedValue = cellStatus.CurrentPiece;
         //compare to confirm match
         //p1 == x, p2 == y
         if (player == CellStates.P1 && displayedValue == CellStatus.Piece.X ||
             player == CellStates.P2 && displayedValue == CellStatus.Piece.O)
         {
             matches++;
         }
     }
     return matches == coordinates.Length;
 }
Example #57
0
 public Cell(CellStates cellState)
 {
     this.cellState = cellState;
 }
Example #58
0
        private int CalculateNorthSouthValue(int row, int column, CellStates player, CellStates opponent)
        {
            int grandTotal = 0;
            int ownedPieces = 0;
            int lostPieces = 0;
            bool blocked = false;

            for (int r = Math.Max(row - (_game.PiecesToWin - 1), 0); r <= Math.Min(_game.Rows - _game.PiecesToWin, row); r++)
            {
                blocked = false;
                ownedPieces = 0;
                lostPieces = 0;

                for (int offset = 0; offset < _game.PiecesToWin; offset++)
                {

                    CellStates cellState = CellStates.Empty;
                    switch (_game.Board[r + offset, column])
                    {
                        case Players.Black:
                            cellState = CellStates.Black;
                            break;
                        case Players.Red:
                            cellState = CellStates.Red;
                            break;
                    }

                    if (cellState == opponent)
                    {
                        // this iteration should add 0 value
                        lostPieces++;
                        blocked = true;
                    }
                    else if (cellState == player)
                    {
                        ownedPieces++;
                    }
                    else
                    {
                        // do nothing if this is a blank cell
                    }
                }

                if (!blocked)
                {
                    if (ownedPieces >= _game.PiecesToWin)
                        grandTotal = 20000;
                    else
                        grandTotal += 2 ^ ownedPieces;
                }
                else if (lostPieces == (_game.PiecesToWin - 1) && ownedPieces == 1)
                {
                    // if this is a true block, make its value fall midway between a win, and 1 away from a win
                    grandTotal += (2 ^ (_game.PiecesToWin - 1) + (2 ^ _game.PiecesToWin - 2));
                }

            }

            return grandTotal;
        }
Example #59
0
        private string GetImageURL(CellStates states)
        {
            switch(states)
            {
                case (CellStates.Floor): return "images/F.png";
                case (CellStates.Wall): return "images/W.png";
                case (CellStates.FloorCrate): return "images/C.png";
                case (CellStates.FloorGoal): return "images/G.png";
                case (CellStates.FloorPlayer): return "images/P.png";
                case (CellStates.FloorGoalPlayer): return "images/GP.png";
                case (CellStates.FloorGoalCrate): return "images/GC.png";

                default:
                    return "images/FV.png";
            }
        }
Example #60
0
		DrawableCellStates(CellStates value)
		{
			this.value = value;
		}