private void SetUpSettings() { settings = MinesweeperGame.Settings; operators = settings.Operators; FirstGuess = settings.FirstGuess; x = settings.x; y = settings.y; numberofmines = settings.NumberOfMines; firststeprule = settings.FirstStepRule; rendering = settings.Rendering; usagemode = settings.usageMode; // if (usagemode == MinesweeperUsageMode.NoAI) { ClickToStep = false; useai = false; } originally the user could player but this functionality was removed if (usagemode == MinesweeperUsageMode.ClickToStepAI) { ClickToStep = true; useai = true; } else { ClickToStep = false; useai = true; } samplesize = settings.SampleSize; sleeptime = settings.SleepTime; solvertype = settings.SolverType; guessor = settings.guessorType; MGDSSP_UncoverMax = settings.MGDSSP_UncoverMax; updatetime = settings.DefaultSolvingSpeed; thinkingtime.text = updatetime.ToString(); gamestate = MinesweeperGame.Gamestate; relativenumberofmines = (float)settings.NumberOfMines / (settings.x * settings.y); MaxSolvingLength = settings.MaxSolvingLength; }
public void UpdateVisualMinesweeperComplete(MinesweeperGamestate gamestate) { if (precheck) { resolutioncheck(); visual.UpdateVisualMinesweeperComplete(gamestate); } }
private static Vector2Int[] OnFlag(MinesweeperGamestate tiles, Vector2Int tile) { tiles[tile].flaged = true; if (tiles[tile].value < 9) { Debug.Log("Non-mine flaged, Game Over"); tiles.GameOver = true; } return(new Vector2Int[] { tile }); }
public override void UpdateVisualMinesweeperComplete(MinesweeperGamestate gamestate) { List <int> state = new List <int>(gamestate.LengthX * gamestate.LengthY); for (int y = 0; y < gamestate.LengthY; y++) { for (int x = 0; x < gamestate.LengthX; x++) { state.Add(GetSpriteId(gamestate[x, y])); } } textureMap.UpdateComplete(state); clearHighlightTiles(); }
GetRequestedMinesweeperElementInfos(MinesweeperGamestate gamestate, KeyValuePair <AIDataType, Vector2Int[]>[] request) { KeyValuePair <AIDataType, KeyValuePair <Vector2Int, MinesweeperElementInfo>[]>[] newanswer = new KeyValuePair <AIDataType, KeyValuePair <Vector2Int, MinesweeperElementInfo>[]> [request.Length]; for (int i = 0; i < request.Length; i++) { KeyValuePair <Vector2Int, MinesweeperElementInfo>[] currentrequest = MinesweeperElementInfo.GetFilteredTiles(gamestate, request[i].Value); newanswer[i] = new KeyValuePair <AIDataType, KeyValuePair <Vector2Int, MinesweeperElementInfo>[]> ( request[i].Key, currentrequest ); } return(newanswer); }
private static Vector2Int[] OnReveal(MinesweeperGamestate tiles, Vector2Int tile, Vector2Int[] operators) { //creating local variable resuting in mminimal performance boost int maxx = tiles.LengthX; int maxy = tiles.LengthY; List <Vector2Int> NeedUpdate = new List <Vector2Int>(); List <Vector2Int> opentiles = new List <Vector2Int>(); if (tiles[tile].hidden && !tiles[tile].flaged) { if (tiles[tile].value == 0) { opentiles.Add(tile); } else if (tiles[tile].value >= 9) { Debug.Log("Game Over"); tiles.GameOver = true; } tiles[tile].hidden = false; NeedUpdate.Add(tile); } while (opentiles.Count != 0) { for (int i = 0; i < operators.Length; i++) { Vector2Int current = opentiles[0] + operators[i]; if (MinesweeperElementInfo.InBounds(current, maxx, maxy)) { if (tiles[current].hidden) { tiles[current].hidden = false; NeedUpdate.Add(current); if (tiles[current].value == 0) { opentiles.Add(current); } } } } opentiles.RemoveAt(0); } return(NeedUpdate.ToArray()); }
/// <summary> /// Returns part of the board requested with the 'filter' parameter /// </summary> /// <param name="board"></param> /// <param name="filter"></param> /// <returns></returns> public static KeyValuePair <Vector2Int, MinesweeperElementInfo>[] GetFilteredTiles(MinesweeperGamestate board, Vector2Int[] filter) { KeyValuePair <Vector2Int, MinesweeperElementInfo>[] filtered = new KeyValuePair <Vector2Int, MinesweeperElementInfo> [filter.Length]; for (int i = 0; i < filter.Length; i++) { Vector2Int current = filter[i]; filtered[i] = new KeyValuePair <Vector2Int, MinesweeperElementInfo>(current, board[current]); } return(filtered); }
public abstract void UpdateVisualMinesweeperComplete(MinesweeperGamestate gamestate);
public static Vector2Int[] OnStep(KeyValuePair <MinesweeperActionType, Vector2Int> step, MinesweeperGamestate tiles, Vector2Int[] operators) { if (step.Key == MinesweeperActionType.Uncover) { return(OnReveal(tiles, step.Value, operators)); } else { return(OnFlag(tiles, step.Value)); } }
/// <summary> /// The first action commited by the player /// </summary> /// <param name="tiles"></param> /// <param name="firststep"></param> /// <param name="rule"></param> /// <param name="operators"></param> public static Vector2Int[] FirstOnReveal(MinesweeperGamestate tiles, Vector2Int firststep, MinesweeperFirstStepRule rule, Vector2Int[] operators) { //creating local variable resuting in miminimal performance boost int maxx = tiles.LengthX; int maxy = tiles.LengthY; if (rule == MinesweeperFirstStepRule.SafeSouranding) { //finding the 'safe tiles' List <Vector2Int> safe = new List <Vector2Int>(); for (int i = 0; i < operators.Length; i++) { Vector2Int current = firststep + operators[i]; if (MinesweeperElementInfo.InBounds(current, maxx, maxy)) { safe.Add(current); } } safe.Add(firststep); //remove mines from 'safe tiles' List <Vector2Int> bombpositions = new List <Vector2Int>(); for (int i = 0; i < safe.Count; i++) { if (tiles[safe[i]].value >= 9) { tiles[safe[i]].value = 0; bombpositions.Add(safe[i]); } } //recalculate value of mines inside, and the souranding of 'safe' tiles for (int i = 0; i < bombpositions.Count; i++) { for (int j = 0; j < operators.Length; j++) { Vector2Int current = bombpositions[i] + operators[j]; if (MinesweeperElementInfo.InBounds(current, maxx, maxy)) { if (tiles[current].value >= 9) { tiles[bombpositions[i]].value++; } else if (!bombpositions.Contains(current)) { tiles[current].value--; } } } } //reassigning mines [not fixed time], but faster List <Vector2Int> newbombs = new List <Vector2Int>(); while (bombpositions.Count != newbombs.Count) { Vector2Int current = new Vector2Int(Random.Range(0, maxx), Random.Range(0, maxy)); if (tiles[current].value < 9 && !safe.Contains(current)) { tiles[current].value = 9; newbombs.Add(current); } } //recalculate souranding of the new mines for (int i = 0; i < newbombs.Count; i++) { for (int j = 0; j < operators.Length; j++) { Vector2Int current = newbombs[i] + operators[j]; if (MinesweeperElementInfo.InBounds(current, maxx, maxy)) { tiles[current].value++; } } } } else if (rule == MinesweeperFirstStepRule.SafeTile) { //firststep if (tiles[firststep].value >= 9) { tiles[firststep].value = 0; //recalculate value of firststep, and it's souranding for (int i = 0; i < operators.Length; i++) { Vector2Int current = firststep + operators[i]; if (MinesweeperElementInfo.InBounds(current, maxx, maxy)) { if (tiles[current].value >= 9) { tiles[firststep].value++; } else { tiles[current].value--; } } } //reassigning mine, and recalculate it's souranding while (true) { Vector2Int current = new Vector2Int(Random.Range(0, maxx), Random.Range(0, maxy)); if (tiles[current].value < 9 && current != firststep) { tiles[current].value = 9; for (int i = 0; i < operators.Length; i++) { Vector2Int current2 = current + operators[i]; if (MinesweeperElementInfo.InBounds(current2, maxx, maxy)) { tiles[current2].value++; } } break; } } if (tiles[firststep].value >= 9) { throw new System.Exception(); } } } return(OnReveal(tiles, firststep, operators)); }