Beispiel #1
0
 private void CheckCaptureURDiagonal(int x, int y)
 {
     try {
         Stone[,] stones = gameScreen.Stones;
         StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;
         if (x + 1 > stones.GetLength(1) - 1 || y - 1 < 0)
         {
             return;
         }
         if (stones[y - 1, x + 1].CurrentState == currentState || stones[y - 1, x + 1].CurrentState == StoneState.Open)
         {
             return;
         }
         if (x + 2 > stones.GetLength(1) - 1 || y - 1 < 0)
         {
             return;
         }
         if (stones[y - 2, x + 2].CurrentState == currentState || stones[y - 2, x + 2].CurrentState == StoneState.Open)
         {
             return;
         }
         if (x + 3 > stones.GetLength(1) - 1 || y - 1 < 0)
         {
             return;
         }
         if (stones[y - 3, x + 3].CurrentState != currentState)
         {
             return;
         }
         CurrentPlayer.Captures++;
         stones[y - 1, x + 1].CurrentState = StoneState.Open;
         stones[y - 2, x + 2].CurrentState = StoneState.Open;
     } catch { }
 }
Beispiel #2
0
        public Desk(Game.Game g) : base(sizeX, sizeY, true)
        {
            this.fields = new Stone[sizeX + 1, sizeY + 1];
            this.game   = g;
            this.Pdesk  = ((Game.Game)game).desk;

            // inicialization of labels
            this.fields[0, 0]           = new Stone();
            this.fields[0, 0].Sensitive = false;
            for (uint i = 1; i < fields.GetLength(0); i++)
            {
                this.fields[i, 0] = new Stone();
                this.Attach(fields[i, 0], i, i + 1, 0, 1);
                this.fields[i, 0].Sensitive = false;
                this.fields[i, 0].Show();
                this.fields[i, 0].setChar(i.ToString());

                this.fields[0, i] = new Stone();
                this.Attach(fields[0, i], 0, 1, i, i + 1);
                this.fields[0, i].Sensitive = false;
                this.fields[0, i].Show();
                this.fields[0, i].setChar(i.ToString());
            }

            for (uint j = 1; j < fields.GetLength(1); j++)
            {
                for (uint i = 1; i < fields.GetLength(0); i++)
                {
                    fields[i, j] = new Stone();
                    this.Attach(fields[i, j], i, i + 1, j, j + 1);
                }
            }

            this.Restart();
        }
Beispiel #3
0
        public static bool LessThan(this Stone[,] a, Stone[,] b)
        {
            bool?aHasWhiteFirst = null;

            for (var i = 0; i < a.GetLength(0); i++)
            {
                for (var j = 0; j < b.GetLength(1); j++)
                {
                    if (a[i, j] == Stone.Black && b[i, j] != Stone.Black)
                    {
                        return(true);
                    }
                    if (b[i, j] == Stone.Black && a[i, j] != Stone.Black)
                    {
                        return(false);
                    }
                    if (!aHasWhiteFirst.HasValue && a[i, j] != b[i, j])
                    {
                        // NOTE Neither A nor B is black
                        //      And one has to be white and the other none
                        if (a[i, j] == Stone.White)
                        {
                            aHasWhiteFirst = true;
                        }
                        else
                        {
                            aHasWhiteFirst = false;
                        }
                    }
                }
            }
            return(aHasWhiteFirst == true);
        }
Beispiel #4
0
 public bool IsLinear(int row, int col, ref Stone[,] temps) // (남은 과제)for문을 이용해 간단하게 refactoring해보기!
 {
     if ((GetStonesData(row - 2, col) != null) && AreSameType(row - 2, col, 1, ref temps))
     // (GetStonesData(row-2, col) != null)는 체크 안해봐도 됨!
     // 첫번째 조건에서 false가 나오면 두번째 조건(AreSameType)은 체크하지 않고 넘어가므로 execption이 일어나지 않으리라 예상!
     {
         return(true);
     }
     if ((GetStonesData(row - 1, col) != null) && (GetStonesData(row + 1, col) != null) && AreSameType(row - 1, col, 1, ref temps))
     {
         return(true);
     }
     if ((GetStonesData(row + 2, col) != null) && AreSameType(row, col, 1, ref temps))
     {
         return(true);
     }
     if ((GetStonesData(row, col - 2) != null) && AreSameType(row, col - 2, 2, ref temps))
     {
         return(true);
     }
     if ((GetStonesData(row, col - 1) != null) && (GetStonesData(row, col + 1) != null) && AreSameType(row, col - 1, 2, ref temps))
     {
         return(true);
     }
     if ((GetStonesData(row, col + 2) != null) && AreSameType(row, col, 2, ref temps))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #5
0
 private static IEnumerable <Stone> YieldDiagUp(Stone[,] stones, int i, int j)
 {
     for (var k = 0; i >= k && j + k < stones.GetLength(1); k++)
     {
         yield return(stones[i - k, j + k]);
     }
 }
Beispiel #6
0
        internal static bool Swap(this Stone[,] field, int2 lPos, int2 rPos)
        {
            if (field == null)
            {
                return(false);
            }
            if (!field.InRange(lPos) || !field.InRange(rPos))
            {
                return(false);
            }

            var ls = field.Get(lPos);
            var rs = field.Get(rPos);

            if (ls != null)
            {
                ls.position = rPos;
            }
            if (rs != null)
            {
                rs.position = lPos;
            }

            field.Set(rPos, ls);
            field.Set(lPos, rs);

            return(true);
        }
Beispiel #7
0
 private static IEnumerable <Stone> YieldCol(Stone[,] stones, int col)
 {
     for (var i = 0; i < stones.GetLength(0); i++)
     {
         yield return(stones[i, col]);
     }
 }
Beispiel #8
0
 private static IEnumerable <Stone> YieldRow(Stone[,] stones, int row)
 {
     for (var j = 0; j < stones.GetLength(1); j++)
     {
         yield return(stones[row, j]);
     }
 }
Beispiel #9
0
 private void CheckCaptureDLDiagonal(int x, int y)
 {
     try {
         Stone[,] stones = gameScreen.Stones;
         StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;
         if (x - 1 < 0 || y + 1 > stones.GetLength(0) - 1)
         {
             return;
         }
         if (stones[y + 1, x - 1].CurrentState == currentState || stones[y + 1, x - 1].CurrentState == StoneState.Open)
         {
             return;
         }
         if (x - 2 < 0 || y + 2 > stones.GetLength(0) - 1)
         {
             return;
         }
         if (stones[y + 2, x - 2].CurrentState == currentState || stones[y + 2, x - 2].CurrentState == StoneState.Open)
         {
             return;
         }
         if (x - 3 < 0 || y + 3 > stones.GetLength(0) - 1)
         {
             return;
         }
         if (stones[y + 3, x - 3].CurrentState != currentState)
         {
             return;
         }
         CurrentPlayer.Captures++;
         stones[y + 1, x - 1].CurrentState = StoneState.Open;
         stones[y + 2, x - 2].CurrentState = StoneState.Open;
     } catch { }
 }
Beispiel #10
0
        private bool CheckDiagonalTria(int x, int y)
        {
            StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;

            Stone[,] stones = gameScreen.Stones;
            bool tria = false;

            if (x - 1 >= 0 && y - 1 >= 0 && stones[y - 1, x - 1].CurrentState == StoneState.Open)
            {
                if (x + 1 <= stones.GetLength(1) - 1 && y - 1 <= stones.GetLength(0) - 1 &&
                    stones[y + 1, x + 1].CurrentState == StoneState.Open)
                {
                    tria = CheckDiagDLtoURTria(currentState, stones, x, y);
                }
                else if (x + 1 <= stones.GetLength(1) - 1 && y + 1 <= stones.GetLength(0) - 1 &&
                         stones[y + 1, x + 1].CurrentState == currentState)
                {
                    if (x + 2 <= stones.GetLength(1) - 1 && y + 2 <= stones.GetLength(0) - 1 &&
                        stones[y + 2, x + 2].CurrentState == currentState)
                    {
                        if (x + 3 <= stones.GetLength(1) - 1 && y + 3 <= stones.GetLength(0) - 1 &&
                            stones[y + 3, x + 3].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            else if (x + 1 <= stones.GetLength(1) - 1 && y + 1 <= stones.GetLength(0) - 1 &&
                     stones[y + 1, x + 1].CurrentState == StoneState.Open)
            {
                if (x - 1 >= 0 && y - 1 >= 0 && stones[y - 1, x - 1].CurrentState == currentState)
                {
                    if (x - 2 >= 0 && y - 2 >= 0 && stones[y - 2, x - 2].CurrentState == currentState)
                    {
                        if (x - 3 >= 0 && y - 3 >= 0 && stones[y - 3, x - 3].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            else if (x + 1 <= stones.GetLength(1) - 1 && y + 1 <= stones.GetLength(0) - 1 &&
                     stones[y + 1, x + 1].CurrentState == currentState)
            {
                if (x - 1 >= 0 && y - 1 >= 0 && stones[y - 1, x - 1].CurrentState == currentState)
                {
                    if (x - 2 >= 0 && y - 2 >= 0 && stones[y - 2, x - 2].CurrentState == StoneState.Open)
                    {
                        if (x + 2 <= stones.GetLength(1) - 1 && y + 2 <= stones.GetLength(0) - 1 &&
                            stones[y + 2, x + 2].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            return(tria);
        }
 //initializes turn panels with empty stones
 public void InitializePanel(Stone[,] panel)
 {
     for (int i = 0; i < panel.GetLength(0); i++)
     {
         for (int j = 0; j < panel.GetLength(1); j++)
         {
             panel[i, j] = new Stone(i, j);
         }
     }
 }
Beispiel #12
0
 public static void Transpose(this Stone[,] input)
 {
     for (var i = 1; i < input.GetLength(0); i++)
     {
         for (var j = 0; j < i; j++)
         {
             Swap(ref input[i, j], ref input[j, i]);
         }
     }
 }
Beispiel #13
0
 public MultiPlayForm()
 {
     InitializeComponent();
     this.playButton.Enabled = false;
     playing   = false;
     entered   = false;
     threading = false;
     board     = new Stone[edgeCount, edgeCount];
     nowTurn   = false;
 }
Beispiel #14
0
 public void Refresh()
 {
     stones = new Stone[boardSize, boardSize];// 바둑판을 그림
     for (int row = 0; row < boardSize; row++)
     {
         for (int col = 0; col < boardSize; col++)
         {
             stones[row, col] = new Stone(row, col, random);
         }
     }
 }
Beispiel #15
0
        public static void MirrorVertical(this Stone[,] input)
        {
            var height = input.GetLength(0);

            for (var i = 0; i < height / 2; i++)
            {
                for (var j = 0; j < input.GetLength(1); j++)
                {
                    Swap(ref input[i, j], ref input[height - 1 - i, j]);
                }
            }
        }
Beispiel #16
0
        public static void MirrorHorizontal(this Stone[,] input)
        {
            var width = input.GetLength(1);

            for (var j = 0; j < width / 2; j++)
            {
                for (var i = 0; i < input.GetLength(0); i++)
                {
                    Swap(ref input[i, j], ref input[i, width - 1 - j]);
                }
            }
        }
Beispiel #17
0
        public BoardNode Place(int x, int y)
        {
            Stone[,] TempBoard = (Stone[, ])BoardState.Clone();

            TempBoard[x, y].SetColor(GetNextColor());

            return(new BoardNode
            {
                BoardSize = BoardSize,
                BoardState = TempBoard
            });
        }
Beispiel #18
0
        private static bool HasAvailableCombo(int2 pos, Stone[,] field)
        {
            foreach (var combo in AllCombos)
            {
                if (combo.HasCombo(pos, field))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #19
0
        public BoardNode Place(Stone stone, Coordinates c)
        {
            Stone[,] TempBoard = CloneBoard().BoardState;

            TempBoard[c.X, c.Y] = stone;

            return(new BoardNode
            {
                BoardSize = BoardSize,
                BoardState = TempBoard
            });
        }
Beispiel #20
0
 public void Init(int size)
 {
     if (!isInited)
     {
         stonesMatrix = new Stone[size, size];
         boardScript.Init(size);
     }
     boardScript.SetOnUserTogglePoint(delegate(Point p)
     {
         this.moveIndicator = p;
         action(p);
     });
 }
 //puts Stones in the 2D array
 public StoneBoard(int boardSize)
 {
     this.rows    = boardSize;
     this.columns = boardSize;
     board        = new Stone[rows, columns];
     for (int i = 0; i < rows; i++)
     {
         for (int j = 0; j < columns; j++)
         {
             board[i, j] = new Stone();
         }
     }
 }
Beispiel #22
0
 public Board()
 {
     Spaces = new Stone[8, 8];
     for (int i = 0; i < Spaces.GetLength(0); i++)
     {
         for (int j = 0; j < Spaces.GetLength(1); j++)
         {
             Spaces[i, j]   = new Stone();
             Spaces[i, j].x = i;
             Spaces[i, j].y = j;
         }
     }
 }
Beispiel #23
0
        public static Stone[,] Copy(this Stone[,] s)
        {
            var copy = new Stone[s.GetLength(0), s.GetLength(1)];

            for (var i = 0; i < s.GetLength(0); i++)
            {
                for (var j = 0; j < s.GetLength(1); j++)
                {
                    copy[i, j] = s[i, j];
                }
            }
            return(copy);
        }
Beispiel #24
0
 public static bool AreEqual(this Stone[,] a, Stone[,] b)
 {
     for (var i = 0; i < a.GetLength(0); i++)
     {
         for (var j = 0; j < b.GetLength(1); j++)
         {
             if (a[i, j] != b[i, j])
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Beispiel #25
0
        private void copyLastGrid()
        {
            if (lastGrid == null)
            {
                lastGrid = new Stone[boardSize, boardSize];
            }

            for (int i = 0; i < boardSize; i++)
            {
                for (int j = 0; j < boardSize; j++)
                {
                    lastGrid[i, j] = grid[i, j];
                }
            }
        }
Beispiel #26
0
        private static Stone FindStoneAbove(Stone[,] field, int2 pos)
        {
            var(_, h) = field;

            for (int y = pos.y + 1; y < h; ++y)
            {
                if (field[pos.x, y] == null)
                {
                    continue;
                }
                return(field[pos.x, y]);
            }

            return(null);
        }
Beispiel #27
0
 public TictactoeSituation(Stone[,] stones)
 {
     this.Stones = stones;
     StoneCount  = 0;
     foreach (var s in stones)
     {
         if (s != Stone.None)
         {
             StoneCount++;
         }
     }
     stones = Stones;
     Normalize(ref stones);
     Stones = stones;
     CalcHash();
 }
Beispiel #28
0
        private bool CheckDiagDLtoURTria(StoneState currentState, Stone[,] stones, int x, int y)
        {
            bool tria      = false;
            int  maxYBound = stones.GetLength(0) - 1;
            int  maxXBound = stones.GetLength(1) - 1;

            if (x + 1 <= maxXBound && y - 1 >= 0 && stones[y - 1, x + 1].CurrentState == StoneState.Open)
            {
                if (x - 1 >= 0 && y + 1 <= maxYBound && stones[y + 1, x - 1].CurrentState == currentState)
                {
                    if (x - 2 >= 0 && y + 2 <= maxYBound && stones[y + 2, x - 2].CurrentState == currentState)
                    {
                        if (x - 3 >= 0 && y + 3 <= maxYBound && stones[y + 3, x - 3].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            else if (x - 1 >= 0 && y + 1 <= maxYBound && stones[y + 1, x - 1].CurrentState == StoneState.Open)
            {
                if (x + 1 <= maxXBound && y - 1 >= 0 && stones[y - 1, x + 1].CurrentState == currentState)
                {
                    if (x + 2 <= maxXBound && y - 2 >= 0 && stones[y - 2, x + 2].CurrentState == currentState)
                    {
                        if (x + 3 <= maxXBound && y - 3 >= 0 && stones[y - 3, x + 3].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            else if (x + 1 <= maxXBound && y - 1 >= 0 && stones[y - 1, x + 1].CurrentState == currentState)
            {
                if (x - 1 >= 0 && y + 1 <= maxYBound && stones[y + 1, x - 1].CurrentState == currentState)
                {
                    if (x - 2 >= 0 && y + 2 <= maxYBound && stones[y + 2, x - 2].CurrentState == StoneState.Open)
                    {
                        if (x + 2 <= maxXBound && y - 2 >= 0 && stones[y - 2, x + 2].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            return(tria);
        }
Beispiel #29
0
        internal static IEnumerable <Stone> SearchStonesInCombo(Stone[,] field)
        {
            var(w, h) = field;

            for (int x = 0; x < w; ++x)
            {
                for (int y = 0; y < h; ++y)
                {
                    if (field[x, y] == null)
                    {
                        continue;
                    }

                    var c = field[x, y].color;

                    if (x < field.GetLength(0) - 2)
                    {
                        var s1       = field[x + 1, y];
                        var s2       = field[x + 2, y];
                        var hasCombo = s1 != null && s2 != null;
                        hasCombo = hasCombo && c == s1.color && c == s2.color;
                        if (hasCombo)
                        {
                            foreach (var s in GetAllWithColor(field, c, new int2(x, y), new int2(1, 0)))
                            {
                                yield return(s);
                            }
                        }
                    }

                    if (y < field.GetLength(1) - 2)
                    {
                        var s1       = field[x, y + 1];
                        var s2       = field[x, y + 2];
                        var hasCombo = s1 != null && s2 != null;
                        hasCombo = hasCombo && c == s1.color && c == s2.color;
                        if (hasCombo)
                        {
                            foreach (var s in GetAllWithColor(field, c, new int2(x, y), new int2(0, 1)))
                            {
                                yield return(s);
                            }
                        }
                    }
                }
            }
        }
Beispiel #30
0
        internal static bool HasAvailableCombo(Stone[,] field)
        {
            var(w, h) = field;

            for (int x = 0; x < w; ++x)
            {
                for (int y = 0; y < h; ++y)
                {
                    if (HasAvailableCombo(new int2(x, y), field))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #31
0
        static void MoveRocksDown()
        {
            Stone[,] temp = new Stone[25, 80];

            for (int i = 0; i < array.GetLength(0); i++)
                for (int j = 0; j < array.GetLength(1); j++)
                    if (i != 24)
                        temp[i + 1, j] = array[i, j];

            array = temp;

            Console.MoveBufferArea(0, 0, y, 24, 0, 1); //Move rocks down a line
            Console.MoveBufferArea(y + 3, 0, 80 - (y + 3), 24, y + 3, 1);
            Console.MoveBufferArea(y, 0, 3, 23, y, 1);
        }
Beispiel #32
0
        /// <summary>
        /// 初期化。
        /// </summary>
        public void Init()
        {
            _board = new Stone[REnvironment.BoardY, REnvironment.BoardX];
            for (int i = 0; i < REnvironment.BoardY; i++)
                for (int j = 0; j < REnvironment.BoardX; j++)
                    _board[i, j] = Stone.None;

            Hand = 1;

            _board[3, 3] = Stone.Black;
            _board[4, 4] = Stone.Black;
            _board[3, 4] = Stone.White;
            _board[4, 3] = Stone.White;

            Living = true;

            ForceLoser = Stone.None;
        }
 private static void FixConsoleScreen()
 {
     Console.WindowHeight = 40;
     consoleHeight = Console.WindowHeight;
     stonesOnScreen = new Stone[consoleHeight - 4, consoleWidth - 1];
     Console.BufferHeight = Console.WindowHeight;
     Console.BufferWidth = Console.WindowWidth;
 }
Beispiel #34
0
 internal PlayingBoard(Stone[,] playingBoard)
 {
     this._playingBoard = playingBoard;
 }