示例#1
0
        public void DiagonalDiffTest_SquareTest()
        {
            var arr = new List <List <int> > {
                new List <int> {
                    18, 4, 6, 5
                },
                new List <int> {
                    8, 2, 7
                },
                new List <int> {
                    21, 9, -13
                }
            };

            Assert.Throws <ArgumentException> (() => Diagonals.DiagonalsDiff(arr));
        }
示例#2
0
        /// <summary>
        /// Place a <paramref name="player"/>'s symbol at a given position.
        /// </summary>
        /// <param name="x">X coordinate of the target position.</param>
        /// <param name="y">Y coordinate of the target position. </param>
        /// <param name="player">Player making this move.</param>
        /// <returns>True if legal move, false otherwise.</returns>
        public bool DoMove(int x, int y, int player)
        {
            if (Values[x][y] != 0)
            {
                return(false);
            }

            Values[x][y] = player;
            if (Values[x].All(v => v == player) ||
                Values.All(a => a[y] == player) ||
                (x == y || y == Size - 1 - x) &&
                Diagonals.Any(diag => diag.All(val => val == player)))
            {
                Winner = player;
            }

            return(true);
        }
示例#3
0
        public void DiagonalDiffTest_DiffTest()
        {
            var arr = new List <List <int> > {
                new List <int> {
                    18, 4, 6
                },
                new List <int> {
                    8, 2, 7
                },
                new List <int> {
                    21, 9, -13
                }
            };
            // D1 = 18 + 2 + -13 = 7
            // D2 = 6 + 2 + 21 = 29
            // abs D1 - D2 = 7 - 29 = -22 = 22
            var result = Diagonals.DiagonalsDiff(arr);

            Assert.True(result == 22, "The abs diff between diagonal must be 22");
        }
示例#4
0
 public void DiagonalDiffTest_ArgumentNull()
 {
     Assert.Throws <ArgumentException> (() => Diagonals.DiagonalsDiff(null));
 }
示例#5
0
        public Square(int index, ContentType content = ContentType.Empty)
        {
            Index   = index;
            Content = content;

            switch (index)
            {
            case 8:
                Corner           = true;
                TopRow           = true;
                Row              = new[] { 8, 3, 4 };
                LeftColumn       = true;
                Column           = new[] { 8, 1, 6 };
                RowOpposite      = 4;
                ColumnOpposite   = 6;
                DiagonalOpposite = 2;
                Diagonals.Add(new[] { 8, 5, 2 });
                break;

            case 3:
                Side           = true;
                TopRow         = true;
                Row            = new[] { 8, 3, 4 };
                MiddleColumn   = true;
                Column         = new[] { 3, 5, 7 };
                ColumnOpposite = 7;
                break;

            case 4:
                Corner           = true;
                TopRow           = true;
                Row              = new[] { 8, 3, 4 };
                RightColumn      = true;
                Column           = new[] { 4, 9, 2 };
                RowOpposite      = 8;
                ColumnOpposite   = 2;
                DiagonalOpposite = 6;
                Diagonals.Add(new[] { 6, 5, 4 });
                break;

            case 1:
                Side        = true;
                MiddleRow   = true;
                Row         = new[] { 1, 5, 9 };
                LeftColumn  = true;
                Column      = new[] { 8, 1, 6 };
                RowOpposite = 9;
                break;

            case 5:
                Center       = true;
                MiddleRow    = true;
                Row          = new[] { 1, 5, 9 };
                MiddleColumn = true;
                Column       = new[] { 3, 5, 7 };
                Diagonals.Add(new[] { 8, 5, 2 });
                Diagonals.Add(new[] { 6, 5, 4 });
                break;

            case 9:
                Side        = true;
                MiddleRow   = true;
                Row         = new[] { 1, 5, 9 };
                RightColumn = true;
                Column      = new[] { 4, 9, 2 };
                RowOpposite = 1;
                break;

            case 6:
                Corner           = true;
                BottomRow        = true;
                Row              = new[] { 6, 7, 2 };
                LeftColumn       = true;
                Column           = new[] { 8, 1, 6 };
                RowOpposite      = 2;
                ColumnOpposite   = 8;
                DiagonalOpposite = 4;
                Diagonals.Add(new[] { 6, 5, 4 });
                break;

            case 7:
                Side           = true;
                MiddleColumn   = true;
                Column         = new[] { 3, 5, 7 };
                BottomRow      = true;
                Row            = new[] { 6, 7, 2 };
                ColumnOpposite = 3;
                break;

            case 2:
                Corner           = true;
                BottomRow        = true;
                Row              = new[] { 6, 7, 2 };
                RightColumn      = true;
                Column           = new[] { 4, 9, 2 };
                RowOpposite      = 6;
                ColumnOpposite   = 4;
                DiagonalOpposite = 8;
                Diagonals.Add(new[] { 8, 5, 2 });
                break;

            default:
                throw new AccessViolationException();
            }
        }
示例#6
0
 public static Vector2 ToVector2(this Diagonals diagonal)
 {
     return(vectors[(int)diagonal]);
 }
示例#7
0
 public static Point ToOppositePoint(this Diagonals diagonal)
 {
     return(points[(int)diagonal % 4]);
 }
示例#8
0
 public static Point ToPoint(this Diagonals diagonal)
 {
     return(points[(int)diagonal]);
 }
示例#9
0
 public static int ToOppositeInt(this Diagonals diagonal)
 {
     return((int)diagonal % 4);
 }
示例#10
0
 public static int ToInt(this Diagonals diagonal)
 {
     return((int)diagonal);
 }