//0 = left, 1 = right, 2 = up, 3 = down
        //Returns true and performs the move
        //if the move is possible, returns false otherwise
        bool Move(int direction)
        {
            int greencountOrig = greenCount;
            Location original = new Location(CurrentX, CurrentY);
            bool continuing = true;
            bool firstMoveDone = false;

            while (continuing)
            {
                continuing = TryStep(direction);
                if (continuing)
                {
                    firstMoveDone = true;
                }
            }
            if(firstMoveDone)
            {
                lastDirection = direction;
                undoData.PushMove(new SingleUndoMoveData(currentMoveList), original);
                currentMoveList.Clear();
                TryMoves();
            }

            return firstMoveDone;
        }
 public GridLocation(Location location)
 {
     this.location = location;
 }
 public MortalCoilMove(MortalCoilMove originalData)
 {
     this.locations = originalData.CloneStack();
     this.firstMove = originalData.firstMove;
     this.originalLoc = originalData.originalLoc;
 }
 public void PushStep(Location loc)
 {
     if (locations.Count == 0)
     {
         this.firstMove = loc;
     }
     locations.Add(loc);
 }
 public void PushMove(MortalCoilMove move, Location originalLoc)
 {
     if (moves.Count == 0)
     {
         this.firstMove = move;
         this.originalLocation = originalLoc;
     }
     moves.Add(move);
     stackCount++;
 }
 public MortalCoilMove(Location originalLoc)
 {
     this.originalLoc = originalLoc;
     locations = new List<Location>();
 }
        public string CreateSolutionText()
        {
            List<MortalCoilMove> s1 = new List<MortalCoilMove>(moves);

            List<Location> locations = new List<Location>();
            locations.Add(originalLocation);

            for(int i = 0; i < s1.Count; i++)
            {
                MortalCoilMove move = s1[i];

                for (int j = 0; j < move.Count; j++)
                {
                    locations.Add(move.locations[j]);
                }
            }

            char[] moveChars = new char[locations.Count - 1];

            for (int i = 1; i < locations.Count; i++)
            {
                Location l = new Location(locations[i].x - locations[i - 1].x,
                    locations[i].y - locations[i - 1].y);
                if (l.x > 0)
                    moveChars[i-1] = ('R');
                else if (l.x < 0)
                    moveChars[i - 1] = ('L');
                else if (l.y < 0)
                    moveChars[i - 1] = ('D');
                else if (l.y > 0)
                    moveChars[i - 1] = ('U');
            }

            string beginURL = @"http://www.hacker.org/coil/index.php?name=Allosentient&password=XXXXX&path=";
            string moveListString = new string(moveChars);
            string originalLocString = @"&x=" + (originalLocation.x - 1).ToString() +
                @"&y=" + (sizeY - originalLocation.y - 2).ToString();

            return (beginURL + moveListString + originalLocString);
        }
Example #8
0
 public GridLocation(Location location)
 {
     this.location = location;
     this.neighborCount = -2;
 }
        //0 = left, 1 = right, 2 = up, 3 = down
        //
        //Returns false if the move minus two causes a dead end
        bool Move(int direction)
        {
            GridLocation oldLocation;
            GridLocation newLocation;

            //Decrement neighbors count for current loc when beginning move
            //Decrement neighbors count for each location moved
            //Increment neighbors count for the final step (only if first move done)
            //Check only the previous squares for neighbor counts

            //Check move minus two for neighbors, and only call tryMoves if it is good

            int greencountOrig = greenCount;
            Location original = new Location(CurrentX, CurrentY);
            currentMoveList.OriginalLocation = original;
            oldLocation = newLocation = grid.Locations[CurrentX, CurrentY];
            bool continuing = true;
            bool firstMoveDone = false;

            while (continuing)
            {
                oldLocation = newLocation;
                continuing = TryStep(direction, out newLocation);
                if (continuing)
                {
                    if (!firstMoveDone)
                    {
                        firstMoveDone = true;
                        locationsAltered.Clear();
                    }
                    locationsAltered.Add(oldLocation);
                    firstMoveDone = true;
                }
            }
            if(firstMoveDone)
            {
                grid.Locations[original.x, original.y].Status = GridLocationStatus.PreviousMoverLocation;
                //Check moveMinusTwo

              //      DebugMoveList(true);
                /*
                bool good = grid.ValidateMoveList(moveMinusTwo);

                    moveMinusTwo = previousMoveList;

                    newLocation = oldLocation;
                    oldLocation = locationsAltered[locationsAltered.Count - 1];
                    locationsAltered.Remove(oldLocation); //remove the last one as it is adjacent
                    previousMoveList = new List<GridLocation>(locationsAltered);
                    previousMoveList.Add(oldLocation);

                    lastDirection = direction;
                 * */

                    MortalCoilMove newMove = new MortalCoilMove(currentMoveList);

                    bool good = grid.ValidateMove(newMove);
                    if (good)
                        moveManager.PushMove(newMove, original);
                    else
                    {
                        foreach (Location location1 in newMove.locations)
                        {
                            grid.Locations[location1.x, location1.y].Status = GridLocationStatus.FreeSquare;
                            levelDataArray[location1.x, location1.y] =
                                originalLevelDataArray[location1.x, location1.y];
                            greenCount--;
                        }

                        CurrentX = original.x; //Reset current location
                        CurrentY = original.y;
                    }
                    currentMoveList.Clear();

                    //if no dead end due to previous move minus two, tryMoves

                    DebugMoveList(true);
                    if (good)
                    {
                        TryMoves();
                    }
                    else
                    {
                  //      DebugMoveList(true);
                        return false;

                       // Stuck();

                    }

            }

            return true;
        }