예제 #1
0
        public void Traverse(int i, int j)
        {
            PathCard pCard = board[i, j];

            if (pCard.Reachable) // meaning visited
            {
                return;          // to prevent closed loop
            }
            pCard.Reachable = true;
            Console.WriteLine("[BOARD] ({0}, {1}) is Reachable", i, j);

            if (IsEmptyPathCard(pCard))
            {
                return;  // if empty card, then no further traverse
            }
            if (!BoundaryFromUp(i, j))
            {
                //PathCard next = board[i - 1, j];
                //if (!IsEmptyPathCard(next))
                //    Traverse(i - 1, j);
                if (pCard.ports["toUp"])
                {
                    Traverse(i - 1, j);
                }
            }

            if (!BoundaryFromDown(i, j))
            {
                //PathCard next = board[i + 1, j];
                //if (!IsEmptyPathCard(next))
                //    Traverse(i + 1, j);
                if (pCard.ports["toDown"])
                {
                    Traverse(i + 1, j);
                }
            }

            if (!BoundaryFromLeft(i, j))
            {
                //PathCard next = board[i, j - 1];
                //if (!IsEmptyPathCard(next))
                //    Traverse(i, j - 1);
                if (pCard.ports["toLeft"])
                {
                    Traverse(i, j - 1);
                }
            }

            if (!BoundaryFromRight(i, j))
            {
                //PathCard next = board[i, j + 1];
                //if (!IsEmptyPathCard(next))
                //    Traverse(i, j + 1);
                if (pCard.ports["toRight"])
                {
                    Traverse(i, j + 1);
                }
            }
        }
예제 #2
0
        public bool RockFall(Card on)
        {
            if (!(on.Position == Status.onBoard) || (on is TreasureCard) || on.Id > 20)
            {
                return(false);
            }

            Console.WriteLine("[ACTION] Rock falls on path card ({0})!", on.Id);
            PathCard pCard = on as PathCard;

            pCard.Id = 100;
            pCard.UpdatePorts();
            return(true);
        }
예제 #3
0
        public Tuple <int, int> SearchCard(PathCard pCard)
        {
            for (int i = 0; i < board.GetLength(0); i++)
            {
                for (int j = 0; j < board.GetLength(1); j++)
                {
                    if (board[i, j] == pCard)
                    {
                        return(Tuple.Create(i, j));
                    }
                }
            }

            return(Tuple.Create(-1, -1));
        }
예제 #4
0
        private void Initialize()
        {
            board     = new PathCard[5, 9];
            startCard = new PathCard(16, Status.onBoard);

            _treasureCards = TreasureCard.CreateTreasureCards();

            for (int i = 0; i < board.GetLength(0); i++)
            {
                for (int j = 0; j < board.GetLength(1); j++)
                {
                    if (board[i, j] == null)
                    {
                        board[i, j] = new PathCard(100, Status.onBoard);
                    }
                }
            }
        }
예제 #5
0
        public bool PlaceCard(Card from, int i, int j, PlayerModel user)  // from = (from player's hand); to = (to target)
        {
            if (from is null)
            {
                return(false);
            }
            if (from is ActionCard)
            {
                if ((from as ActionCard).type == ActionType.rockFall && i == 2 && j == 0)
                {
                    return(false);
                }
            }

            PathCard to = board[i, j];

            Console.WriteLine("[BOARD] Trying to place ({0}) on ({1}) with location ({2}, {3})", from.Id, to.Id, i, j);

            if (from is PathCard)
            {
                if (!PathCardPlaceable(from as PathCard, i, j))
                {
                    return(false);
                }

                to.Id = from.Id;
                to.UpdatePorts();
                from.Id = 100;  // empty
                return(true);
            }
            else if (from is ActionCard)
            {
                return((from as ActionCard).UseOnBoard(to, user));
            }
            else
            {
                return(false);
            }
        }
예제 #6
0
        public bool PathCardPlaceable(PathCard pCard, int i, int j)
        {
            if (i == -1 || j == -1)
            {
                Console.WriteLine("[ERROR] Coordinate tuple has -1. Serious Error");
                return(false);
            }

            PathCard to = board[i, j];

            if (!IsEmptyPathCard(to))
            {
                Console.WriteLine("[BOARD] Invalid connection, target no empty");
                return(false);
            }

            if (!NotIsolated(i, j))
            {
                Console.WriteLine("[BOARD] Invalid connection, target is isolated");
                return(false);
            }

            if (!to.Reachable)
            {
                Console.WriteLine("[BOARD] Invalid connection, target not reachable");
                return(false);
            }

            // check whether the connections of ports are appropriate
            bool flag = true;

            if (HaveCardFromUp(i, j))
            {
                if (!(board[i - 1, j] is TreasureCard))  // it is okay not to have ports towards a TreasureCard
                {
                    flag &= !(pCard.ports["toUp"] ^ NeedPortTowardsUp(i, j));
                }
            }
            if (HaveCardFromDown(i, j))
            {
                if (!(board[i + 1, j] is TreasureCard))
                {
                    flag &= !(pCard.ports["toDown"] ^ NeedPortTowardsDown(i, j));
                }
            }
            if (HaveCardFromLeft(i, j))
            {
                if (!(board[i, j - 1] is TreasureCard))
                {
                    flag &= !(pCard.ports["toLeft"] ^ NeedPortTowardsLeft(i, j));
                }
            }
            if (HaveCardFromRight(i, j))
            {
                if (!(board[i, j + 1] is TreasureCard))
                {
                    flag &= !(pCard.ports["toRight"] ^ NeedPortTowardsRight(i, j));
                }
            }

            /*if (NeedPortTowardsUp(i, j))
             *  flag &= pCard.ports["toUp"];
             * if (NeedPortTowardsDown(i, j))
             *  flag &= pCard.ports["toDown"];
             * if (NeedPortTowardsLeft(i, j))
             *  flag &= pCard.ports["toLeft"];
             * if (NeedPortTowardsRight(i, j))
             *  flag &= pCard.ports["toRight"];
             */

            if (flag)
            {
                Console.WriteLine("[BOARD] Yes, card({0}) placeable at ({1}, {2})", pCard.Id, i, j);
            }
            else
            {
                Console.WriteLine("[BOARD] No, wrong ports, card({0}) NOT placeable at ({1}, {2})", pCard.Id, i, j);
            }

            return(flag);
        }
예제 #7
0
 public bool IsEmptyPathCard(PathCard pCard) => pCard.Id == 100;