Esempio n. 1
0
        public bool PutMark(string mark, char marker)
        {
            this.Message = "";
            if (mark.Length != 2)
            {
                this.Message = "Invalid input - 2 haracter, a letter and as number";
                return(false);
            }
            if (!this.ValidRows.Contains(mark.Substring(0, 1)) | !this.ValidCols.Contains(mark.Substring(1, 1)))
            {
                this.Message = "Invalid input - valid inputs are a1, a2, a3, b1, ..., c3";
                return(false);
            }

            byte col = this.RowNumbers[mark.Substring(0, 1)];
            byte row = byte.Parse(mark.Substring(1, 1));
            byte i   = (byte)(col - 1);
            byte j   = (byte)(row - 1);


            if (this.Board[i, j] == 0)
            {
                this.Board[i, j] = marker;
                CheckSurrounding check;
                if (row < 3)
                {
                    check = new CheckSurrounding(this.CheckRight);
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                }
                else if (col == 3)
                {
                    check = new CheckSurrounding(this.CheckLeft);
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                }
                else
                {
                    check = new CheckSurrounding(this.CheckRight);
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                    check = this.CheckLeft;
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                }

                if (row < 3)
                {
                    check = this.CheckBelow;
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                }
                if (row > 1)
                {
                    check = this.CheckAbove;
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                }

                if (col == 2 & row == 2)
                {
                    check = this.CheckRightLower;
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                    check = this.CheckRightUpper;
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                    check = this.CheckLeftUpper;
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                    check = this.CheckLeftLower;
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                }
                else if (col < 3 & row < 3)
                {
                    check = this.CheckRightLower;
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                }
                else if (col < 3 & row == 3)
                {
                    check = this.CheckRightUpper;
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                }
                else if (col > 1 & row < 3)
                {
                    check = this.CheckLeftLower;
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                }
                else if (col > 1 & row == 3)
                {
                    check = this.CheckLeftUpper;
                    if (check(i, j) == null)
                    {
                        return(true);
                    }
                }
            }
            return(true);
        }
Esempio n. 2
0
        public bool PutMark(string mark, char marker)
        {
            this.Message = "";
            if (mark.Length != 2)
            {
                this.Message = "Invalid input - 2 haracter, a letter and as number";
                return false;
            }
            if (!this.ValidRows.Contains(mark.Substring(0,1)) | !this.ValidCols.Contains(mark.Substring(1,1))) {
                this.Message = "Invalid input - valid inputs are a1, a2, a3, b1, ..., c3";
                return false;
            }

            byte col = this.RowNumbers[mark.Substring(0,1)];
            byte row = byte.Parse(mark.Substring(1, 1));
            byte i = (byte)(col - 1);
            byte j = (byte)(row - 1);

            if (this.Board[i, j] == 0 )
            {
                this.Board[i, j] = marker;
                CheckSurrounding check;
                if (row < 3)
                {
                    check = new CheckSurrounding(this.CheckRight);
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                }
                else if (col == 3)
                {
                    check = new CheckSurrounding(this.CheckLeft);
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                }
                else
                {
                    check = new CheckSurrounding(this.CheckRight);
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                    check = this.CheckLeft;
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                }

                if (row < 3)
                {
                    check = this.CheckBelow;
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                }
                if (row > 1)
                {
                    check = this.CheckAbove;
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                }

                if (col == 2 & row == 2)
                {
                    check = this.CheckRightLower;
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                    check = this.CheckRightUpper;
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                    check = this.CheckLeftUpper;
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                    check = this.CheckLeftLower;
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                }
                else if (col < 3 & row < 3)
                {
                    check = this.CheckRightLower;
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                }
                else if (col < 3 & row == 3)
                {
                    check = this.CheckRightUpper;
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                }
                else if (col > 1 & row < 3)
                {
                    check = this.CheckLeftLower;
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                }
                else if (col > 1 & row == 3)
                {
                    check = this.CheckLeftUpper;
                    if (check(i, j) == null)
                    {
                        return true;
                    }
                }

            }
            return true;
        }