Exemple #1
0
        public override List<AbstractMove> GetCaptureMoves(State state,
            List<CoordinatePair> adjacentList, BoardSpace currSpace)
        {
            List<AbstractMove> captureMoves = new List<AbstractMove>();
            int tempRow = 0;
            int tempCol = 0;

            int bRow = 0;
            int bColumn = 0;

            foreach (CoordinatePair b in adjacentList)
            {
                if (state.GetSpaceState(b.Row, b.Column) == 'G')
                {
                    tempRow = currSpace.GetRow();
                    tempCol = currSpace.GetColumn();

                    bRow = b.Row;
                    bColumn = b.Column;

                    if (bRow == currSpace.GetRow())
                    {
                        if (bColumn < currSpace.GetColumn())
                            tempCol = bColumn - 1;
                        if (bColumn > currSpace.GetColumn())
                            tempCol = bColumn + 1;
                    }

                    if (bRow < currSpace.GetRow())
                    {
                        tempRow = bRow - 1;
                        if (bColumn < currSpace.GetColumn())
                            tempCol = bColumn - 1;
                        if (bColumn > currSpace.GetColumn())
                            tempCol = bColumn + 1;
                    }

                    if (bRow > currSpace.GetRow())
                    {
                        tempRow = bRow + 1;
                        if (bColumn < currSpace.GetColumn())
                            tempCol = bColumn - 1;
                        if (bColumn > currSpace.GetColumn())
                            tempCol = bColumn + 1;
                    }

                    if ((tempRow >= 0 && tempRow <= 4) && (tempCol >= 0 && tempCol <= 4))
                        if (state.GetSpaceState(tempRow, tempCol) == 'X')
                            captureMoves.Add(new TigerCaptureMove(currSpace, state
                                    .Board.GetSpace(tempRow, tempCol), state
                                    .Board.GetSpace(bRow, bColumn), this));
                }

            }

            return captureMoves;
        }
Exemple #2
0
        public void TestBoardSpace()
        {
            int row = 0;
            int col = 1;
            BoardSpace bs = new BoardSpace(row, col);
            Console.WriteLine("BoardSpace created: " + bs.ToString());
            Assert.IsNotNull(bs);
            Assert.AreEqual(bs.GetRow(), row);
            Assert.AreEqual(bs.GetColumn(), col);

            row = 1;
            col = 2;
            bs.SetRow(row);
            bs.SetColumn(col);
            Assert.AreEqual(bs.GetRow(), row);
            Assert.AreEqual(bs.GetColumn(), col);

            row = 2;
            col = 3;
            bs.SetCoordinates(row, col);
            Assert.AreEqual(bs.GetRow(), row);
            Assert.AreEqual(bs.GetColumn(), col);

            Assert.AreEqual(bs.GetSpaceState(), 'X');

            bs.SetSpaceState('T');
            Assert.AreEqual(bs.GetSpaceState(), 'T');
            bs.SetSpaceState('G');
            Assert.AreEqual(bs.GetSpaceState(), 'G');
            bs.SetSpaceState('X');
            Assert.AreEqual(bs.GetSpaceState(), 'X');

            try
            {
                bs.SetSpaceState('M');
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Assert.AreEqual(bs.GetSpaceState(), 'X');

            bs = new BoardSpace(1, 3, 'T');
            Assert.AreEqual(bs.GetSpaceState(), 'T');
            Assert.AreEqual(bs.GetRow(), 1);
            Assert.AreEqual(bs.GetColumn(), 3);
            Console.WriteLine("finished TestBoardSpace()");
            //Assert.IsNull(bs.getSpaceState());
        }