private Choosers.BlockGroupChooser GetChooser() { //TODO: proper per-handler configs should include the chooser class to use. var resultChooser = new BagChooser(Tetromino.StandardTetrominoFunctions); return(resultChooser); }
public override BlockGroupChooser GetChooser() { BagChooser bc = new BagChooser(Tetromino.Tetris2TetrominoFunctions); bc.ResultAffector = Tetris2NominoTweaker; return(bc); }
//Runs a simulation with a given piece of scoring data, and board width and height, and runs one simulated game using that scoring for AI determination and //returns a valuation of the resulting gameplay using the scoring algorithm with those weights. public static double RunSimulation(StoredBoardState.TetrisScoringRuleData scoredata, int BoardWidth = 10, int BoardHeight = 22) { Debug.Print($"--------Running Simulation " + scoredata.ToString() + "-----"); //create the chooser. BlockGroupChooser bgc = new BagChooser(Tetromino.StandardTetrominoFunctions); List <Nomino> ChosenNominos = new List <Nomino>(); NominoBlock[][] Contents = new NominoBlock[TetrisField.DEFAULT_ROWCOUNT][]; for (int row = 0; row < TetrisField.DEFAULT_ROWCOUNT; row++) { Contents[row] = new NominoBlock[TetrisField.DEFAULT_COLCOUNT]; } int Placedpieces = 0; int rowsFinished = 9; bool GameEnded = false; int nominoCount = 0; while (!GameEnded) { //get the next Nomino. var nextNomino = bgc.RetrieveNext(); ChosenNominos.Add(nextNomino); //Debug.Print("Processing new Nomino:" + nextNomino.SpecialName); var PossibleBoardResults = StandardNominoAI.GetPossibleResults(Contents, nextNomino, scoredata); //score each one based on the scoring rules. var BestScore = (from p in PossibleBoardResults orderby p.GetScore(typeof(GameStates.GameHandlers.StandardTetrisHandler), scoredata) descending select p).FirstOrDefault(); if (BestScore != null) { // we go with the best scoring value of course. Contents = BestScore.State; String NewStateString = BestScore.GetBoardString(); //Debug.Print("Found best score location for new Nomino. Board State:"); //Debug.Print("\n\n" + NewStateString); Placedpieces++; } int RemoveLines = RemoveFinishedRows(ref Contents); rowsFinished += (RemoveLines * RemoveLines); //square it, reason is to give higher scores for AI that manages to land more multi-line clears. //if the top line has a block than we will consider it Game Ended. if (Contents[0].Any((r) => r != null)) { GameEnded = true; } } //Debug.Print("Final Score:" +rowsFinished + Placedpieces); //Debug.Print($"----------------Completed Simulation Bumpiness:{scoredata.BumpinessScore}, Height:{scoredata.AggregateHeightScore}, Hole:{scoredata.HoleScore}, Row:{scoredata.RowScore} --------"); return(rowsFinished + Placedpieces); //return score for this simulation. }
public FieldLineActionDissolve(GameplayGameState _BaseState, int[] ClearRows, IEnumerable <Action> pAfterClearActions) : base(_BaseState, ClearRows, pAfterClearActions) { List <Point> AllBlockPositions = new List <Point>(); RowClearCount = ClearRows.Length; foreach (int grabrow in ClearRows) { var rowcontent = _BaseState.PlayField.Contents[grabrow]; for (int addblock = 0; addblock < rowcontent.Length; addblock++) { if (rowcontent[addblock] != null) { AllBlockPositions.Add(new Point(grabrow, addblock)); } } } ClearBlockList = new Queue <Point>(); foreach (var choosernd in BagChooser.Shuffle(new Random(), AllBlockPositions)) { ClearBlockList.Enqueue(choosernd); } }
public static Choosers.BlockGroupChooser BagTetrominoChooser() { BlockGroupChooser Chooser = new BagChooser(StandardTetrominoFunctions); return(Chooser); }