Exemple #1
0
        public bool TryPut(ChipState chip, out ChipPlace chipPlace)
        {
            chipPlace = null;
            var  footPos = chip.Foot;
            var  xOffset = CurrentTestPosition.X - footPos.X;
            var  yOffset = CurrentTestPosition.Y - footPos.Y;
            bool test    = true;

            for (int x = 0; x < Chip.MatrixSize; x++)
            {
                for (int y = 0; y < Chip.MatrixSize; y++)
                {
                    var posx = xOffset + x;
                    var posy = yOffset + y;
                    if (chip.Matrix[x, y] != 0 &&
                        (posx < 0 || posx >= XSize || posy < 0 || posy >= YSize || Matrix[xOffset + x, yOffset + y] != 0))
                    {
                        test = false;
                        break;
                    }
                }
            }

            if (test)
            {
                chipPlace = new ChipPlace
                {
                    ChipPosition = new Position
                    {
                        X = CurrentTestPosition.X,
                        Y = CurrentTestPosition.Y
                    },
                    Mark = chipMark
                };
                for (int x = 0; x < Chip.MatrixSize; x++)
                {
                    for (int y = 0; y < Chip.MatrixSize; y++)
                    {
                        if (chip.Matrix[x, y] != 0)
                        {
                            Matrix[xOffset + x, yOffset + y] = chipMark;
                        }
                    }
                }
                chipMark++;
                MoveToNextPosition();
            }
            return(test);
        }
Exemple #2
0
 public void Remove(ChipPlace chipPlace)
 {
     for (int y = 0; y < YSize; y++)
     {
         for (int x = 0; x < XSize; x++)
         {
             if (Matrix[x, y] == chipPlace.Mark)
             {
                 Matrix[x, y] = 0;
             }
         }
     }
     CurrentTestPosition = chipPlace.ChipPosition;
     chipMark--;
 }