예제 #1
0
        //CHANGED NOW
        public Player.NeighborStatus GetPlayersNeighbor(int column, int row, Team.TeamColor team)
        {
            /* End of the board */
            if ((column < 0) || (row < 0) || (row >= Height) || (column >= Width))
            {
                return(Player.NeighborStatus.BLOCKED);
            }

            /* Goal Area */
            if (row < GoalHeight)
            {
                if (team == Team.TeamColor.BLUE)
                {
                    Team.TeamCell teamCell = BlueTeam.isDiscovered(column, row);
                    if (teamCell == Team.TeamCell.FREE)
                    {
                        return(Player.NeighborStatus.GOAL_AREA);
                    }
                    if (teamCell == Team.TeamCell.DISCOVERED_GOAL)
                    {
                        return(Player.NeighborStatus.DISCOVERED_GOAL);
                    }
                    if (teamCell == Team.TeamCell.DISCOVERED_NONGOAL)
                    {
                        return(Player.NeighborStatus.DISCOVERED_NONGOAL);
                    }
                }
                else
                {
                    return(Player.NeighborStatus.BLOCKED);
                }
            }
            if (Height - row - 1 < GoalHeight)
            {
                if (team == Team.TeamColor.RED)
                {
                    Team.TeamCell teamCell = RedTeam.isDiscovered(column, row);
                    if (teamCell == Team.TeamCell.FREE)
                    {
                        return(Player.NeighborStatus.GOAL_AREA);
                    }
                    if (teamCell == Team.TeamCell.DISCOVERED_GOAL)
                    {
                        return(Player.NeighborStatus.DISCOVERED_GOAL);
                    }
                    if (teamCell == Team.TeamCell.DISCOVERED_NONGOAL)
                    {
                        return(Player.NeighborStatus.DISCOVERED_NONGOAL);
                    }
                }
                else
                {
                    return(Player.NeighborStatus.BLOCKED);
                }
            }

            /* Other player */
            foreach (Player p in RedTeam.members)
            {
                if (p.Column == column && p.Row == row)
                {
                    return(Player.NeighborStatus.BLOCKED);
                }
            }
            if (RedTeam.leader.Column == column && RedTeam.leader.Row == row)
            {
                return(Player.NeighborStatus.BLOCKED);
            }

            foreach (Player p in BlueTeam.members)
            {
                if (p.Column == column && p.Row == row)
                {
                    return(Player.NeighborStatus.BLOCKED);
                }
            }
            if (BlueTeam.leader.Column == column && BlueTeam.leader.Row == row)
            {
                return(Player.NeighborStatus.BLOCKED);
            }

            /* Piece */
            foreach (Piece p in Pieces)
            {
                if (p.column == column && p.row == row)
                {
                    return(Player.NeighborStatus.PIECE);
                }
            }

            /* Free cell */
            return(Player.NeighborStatus.FREE);
        }
예제 #2
0
        public void TestMethod_ForTeam() /* COMPLETE */
        {
            Player p_blue = new Player()
            {
                role = Player.Role.LEADER,
                //playerID = 0,
                Row    = 0,
                Column = 0,
                //toCheck = true,
                Team = Team.TeamColor.BLUE
            };

            Player p_red = new Player()
            {
                role = Player.Role.LEADER,
                //playerID = 1,
                Row    = 1,
                Column = 10,
                //toCheck = true,
                Team = Team.TeamColor.RED
            };

            List <Player> listp = new List <Player>()
            {
                p_blue, p_red
            };
            Goal g1 = new Goal()
            {
                column = 0,
                row    = 1,
                isGoal = true
            };

            Goal g2 = new Goal()
            {
                column = 1,
                row    = 2,
                isGoal = true
            };

            List <Goal> listg = new List <Goal>()
            {
                g1, g2
            };

            Team t = new Team(Team.TeamColor.BLUE);

            t.members            = listp;
            t.DiscoveredGoals    = listg;
            t.DiscoveredNonGoals = listg;
            Player p = new Player()
            {
                role = Player.Role.LEADER,
                //playerID = 1,
                Row    = 0,
                Column = 1,
                //toCheck = true,
                Team = Team.TeamColor.RED
            };

            t.leader = p;

            int col = 1;
            int row = 0;

            Team.TeamCell expected = Team.TeamCell.FREE;
            int           ex       = 2;

            int actual0 = t.NumOfPlayers;

            Team.TeamCell actual  = t.isTaken(col, row);
            Team.TeamCell actual2 = t.isDiscovered(col, row);
            Assert.AreEqual(ex, actual0);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(expected, actual2);
        }
예제 #3
0
        public Status[,] boardtable; // column row


        public Status getCellStatus(int col, int row)
        {
            if ((col < 0) || (row < 0) || (row >= Height) || (col >= Width))
            {
                return(Status.END_OF_BOARD);
            }

            #region Player Occupation
            /* Check if RED player occupaes a cell */
            if (RedTeam.isTaken(col, row) == Team.TeamCell.PLAYER)
            {
                return(Board.Status.RED_PLAYER);
            }
            else if (RedTeam.isTaken(col, row) == Team.TeamCell.PLAYER_PIECE)
            {
                return(Board.Status.RED_PLAYER_WITH_PIECE);
            }

            /* Check if BLUE player occupaes a cell */
            if (BlueTeam.isTaken(col, row) == Team.TeamCell.PLAYER)
            {
                return(Board.Status.BLUE_PLAYER);
            }
            else if (BlueTeam.isTaken(col, row) == Team.TeamCell.PLAYER_PIECE)
            {
                return(Board.Status.BLUE_PLAYER_WITH_PIECE);
            }
            #endregion

            #region Check if PIECE occupaes a cell
            /* Check if PIECE occupaes a cell */
            foreach (var item in Pieces)
            {
                if (item.isTaken(col, row))
                {
                    if (item.isSham)
                    {
                        return(Board.Status.SHAM);
                    }
                    else
                    {
                        return(Board.Status.PIECE);
                    }
                }
            }
            #endregion

            #region Goal
            /* Checks if GOAL belongs to a SPECIFIC type of goal */
            foreach (var item in UndiscoveredRedGoals)
            {
                if (item.isTaken(col, row))
                {
                    return(Board.Status.UNDISCOVERED_GOAL);
                }
            }

            foreach (var item in UndiscoveredBlueGoals)
            {
                if (item.isTaken(col, row))
                {
                    return(Board.Status.UNDISCOVERED_GOAL);
                }
            }

            foreach (var item in DiscoveredRedGoals)
            {
                if (item.isTaken(col, row))
                {
                    return(Board.Status.DISCOVERED_GOAL);
                }
            }

            foreach (var item in DiscoveredBlueGoals)
            {
                if (item.isTaken(col, row))
                {
                    return(Board.Status.DISCOVERED_GOAL);
                }
            }

            foreach (var item in NonGoals)
            {
                if (item.isTaken(col, row))
                {
                    return(Board.Status.DISCOVERED_NON_GOAL);
                }
            }

            #endregion

            /* Is goal BLUE area */
            if (row < GoalHeight)
            {
                Team.TeamCell teamCell = BlueTeam.isDiscovered(col, row);
                if (teamCell == Team.TeamCell.FREE)
                {
                    return(Board.Status.BLUE_GOALS_CELL);
                }
                if (teamCell == Team.TeamCell.DISCOVERED_GOAL)
                {
                    return(Board.Status.DISCOVERED_GOAL);
                }
                if (teamCell == Team.TeamCell.DISCOVERED_NONGOAL)
                {
                    return(Board.Status.DISCOVERED_NON_GOAL);
                }
            }
            /* Is goal RED area */
            if (Height - row - 1 < GoalHeight)
            {
                Team.TeamCell teamCell = RedTeam.isDiscovered(col, row);
                if (teamCell == Team.TeamCell.FREE)
                {
                    return(Board.Status.RED_GOALS_CELL);
                }
                if (teamCell == Team.TeamCell.DISCOVERED_GOAL)
                {
                    return(Board.Status.DISCOVERED_GOAL);
                }
                if (teamCell == Team.TeamCell.DISCOVERED_NONGOAL)
                {
                    return(Board.Status.DISCOVERED_NON_GOAL);
                }
            }

            return(Board.Status.TASK_CELL);
        }