public MortalCoilMove(MortalCoilMove originalData) { this.locations = originalData.CloneStack(); this.firstMove = originalData.firstMove; this.originalLoc = originalData.originalLoc; }
public void PushMove(MortalCoilMove move, Location originalLoc) { if (moves.Count == 0) { this.firstMove = move; this.originalLocation = originalLoc; } moves.Add(move); stackCount++; }
//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; }
//Decrements the original location and all locations in the move except for the last one //(current location) //Returns false if the move is not possible. The original state will be preserved public bool ValidateMove(MortalCoilMove move) { if(move.Count < 0) { throw new InvalidOperationException(); } bool good = true; GridLocation loc = locations[move.OriginalLocation.x, move.OriginalLocation.y]; if (!DecrementAdjacentNeighbors(loc)) { good = false; /* if (BrokenGrid(loc)) { IncrementAdjacentNeighbors(loc); good = false; } * */ } if(good) { for (int i = 0; i < move.Count - 1; i++) { if(good) { loc = locations[move.locations[i].x, move.locations[i].y]; if (!DecrementAdjacentNeighbors(loc)) { /* if (BrokenGrid(loc)) { * */ good = false; i--; while (i >= 0) { loc = locations[move.locations[i].x, move.locations[i].y]; IncrementAdjacentNeighbors(loc); i--; } // } IncrementAdjacentNeighbors(locations[move.OriginalLocation.x, move.OriginalLocation.y]); } } } } return good; }
/*//////////////////////////////////////////////////////// Methods ////////////////////////////////////////////////////////*/ public override void Initialize() { base.Initialize(); /*///////////////////////////////// Settings /////////////////////////////////*/ #region initsettings graphics.Settings.Display.VSyncEnabled.ClientValue = false; graphics.Settings.Projection.ProjectionType.ClientValue = projectionType; graphics.Settings.Projection.OrthographicBoundary.ClientValue = new FACE_System.Rectangle(0f, 8f, 0f, 6f); graphics.Settings.Projection.OrthographicBoundary.UpdateRateHolding.ClientValue = 0.5f; System.Window.Title = "Client"; System.Graphics.Settings.ScreenArea.WindowSize.ClientVector2D = new Vector2(800f, 600f); double g = graphics.Settings.Projection.ZNear.ClientValue = 1.0; double f = graphics.Settings.Projection.ZFar.ClientValue = 19.001; GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Less); GL.CullFace(CullFaceMode.FrontAndBack); GL.Hint(HintTarget.FogHint, HintMode.Fastest); GL.Hint(HintTarget.GenerateMipmapHint, HintMode.Fastest); GL.Hint(HintTarget.LineSmoothHint, HintMode.Fastest); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Fastest); GL.Hint(HintTarget.PointSmoothHint, HintMode.Fastest); GL.Hint(HintTarget.PolygonSmoothHint, HintMode.Fastest); GL.Hint(HintTarget.TextureCompressionHint, HintMode.Fastest); #endregion /*///////////////////////////////// Buttons /////////////////////////////////*/ #region initbuttons ButtonMapping bMap = System.Input.Settings.ButtonMapSettings.CurrentButtonMap; //Zoom/Pan bMap.AddHotkey(CommonKeyboardKeys.NUMPAD_ADD, FACESystemFunctions.Projection_Ortho_ZoomIn, ButtonMapType.Holding); bMap.AddHotkey(CommonKeyboardKeys.NUMPAD_SUBTRACT, FACESystemFunctions.Projection_Ortho_ZoomOut, ButtonMapType.Holding); bMap.AddHotkey(CommonKeyboardKeys.NUMPAD8, FACESystemFunctions.Projection_Ortho_MoveUp, ButtonMapType.Holding); bMap.AddHotkey(CommonKeyboardKeys.NUMPAD2, FACESystemFunctions.Projection_Ortho_MoveDown, ButtonMapType.Holding); bMap.AddHotkey(CommonKeyboardKeys.NUMPAD4, FACESystemFunctions.Projection_Ortho_MoveLeft, ButtonMapType.Holding); bMap.AddHotkey(CommonKeyboardKeys.NUMPAD6, FACESystemFunctions.Projection_Ortho_MoveRight, ButtonMapType.Holding); bMap.AddHotkey(CommonKeyboardKeys.T, new TimeDependentFunction(SubmitSolutionAndReload), ButtonMapType.JustPressed); bMap.AddHotkey(CommonKeyboardKeys.D, new TimeDependentFunction(ToggleBoardDrawing), ButtonMapType.JustPressed); #endregion /*///////////////////////////////// Data /////////////////////////////////*/ #region initdata greenBox = new Texture2D(@"../../Content/greensquare.bmp"); greyBox = new Texture2D(@"../../Content/greysquare.bmp"); currentStartSprite = new Sprite(system, greenBox); currentStartSprite.Scale = new Vector3(.5f, .5f, 1f); if(levelToGet == -1) GetLevel(@"http://www.hacker.org/coil/index.php?name=Allosentient&password=XXXXX"); else GetLevel(levelToGet); currentMoveList = new MortalCoilMove(new Location(currentStartX, currentStartY)); moveManager = new MortalCoilMoveList(system, sizeY); #endregion }