public double GetScore(Type CustomizationType, StoredBoardState.BoardScoringRuleData Rules) { //Gamehandler types should have an attribute that points to another type implementing the IGameScoringHandler interface. That will accept a board state //and provide the score. var scoreattributes = CustomizationType.GetCustomAttributes(typeof(GameScoringHandlerAttribute), true); if (scoreattributes.Length > 0) { //take the first one. GameScoringHandlerAttribute attrib = scoreattributes.First() as GameScoringHandlerAttribute; return(attrib.Handler.CalculateScore(Rules, this)); } throw new TypeLoadException("Failed to find GameScoringHandler for type " + CustomizationType.GetType().ToString()); //calculate the "value" of this state. //we need: //number of completed rows/lines //Aggregate Height (sum of the height of the highest block in each column) //Holes- where we have null blocks with non-null blocks above it. //bumpiness: sum of the absolute differences of the heights of each adjacent column /* * int Rows = GetCompletedLines(); * int Aggregate = GetAggregateHeight(); * int Holes = GetHoles(); * int Bumpy = GetBumpiness(); * int Crevice = GetCrevasses(); * //Debug.Print("Rows=" + Rows + " Aggregate=" + Aggregate + " Holes=" + Holes + " Bumps=" + Bumpy); * //double a = -0.610066f; * //double b = 0.760666; * //double c = -0.55663; * ////double d = -.184483; * //double d = -.384483; * double CreviceScore = (Rules.CrevasseScore * (double)Crevice); * return (Rules.AggregateHeightScore * (double)Aggregate) + * (Rules.RowScore * (double)Rows) + * (Rules.HoleScore * (double)Holes) + * (Rules.BumpinessScore * (double)Bumpy) + * CreviceScore; */ /*a = -0.510066 * b = 0.760666 * c = -0.35663 * d = -0.184483 * * a+AggregateHeight+b*completelines+c*holes+d*bumpiness*/ }
public double CalculateScore(StoredBoardState.BoardScoringRuleData data, StoredBoardState state) { StoredBoardState.DrMarioScoringRuleData dat = data as StoredBoardState.DrMarioScoringRuleData; var FieldColumnScore = GetFieldColumnScore(dat, state); Debug.Print("Field Column Score:" + FieldColumnScore); double MassScore = 0; foreach (var iterate in FindMasses(dat, state)) { int VirusCount = (from c in iterate.MassContents where c is LineSeriesPrimaryBlock select c).Count(); double AddScore = ((double)VirusCount) * dat.MasterBlockMassValue + iterate.MassSize; MassScore += AddScore; } return(FieldColumnScore + MassScore); //basically random, I think. //throw new NotImplementedException(); }
public static IEnumerable <StoredBoardState> GetPossibleResults(NominoBlock[][] Source, Nomino bg, StoredBoardState.BoardScoringRuleData rules) { //Debug.Print("Calculating possible results:" + Source.Sum((u)=>u.Count((y)=>y!=null)) + " Non null entries."); for (int useRotation = 0; useRotation < 4; useRotation++) { for (int x = -5; x < Source[0].Length + 5; x++) { if (rules.StupidFactor < 1) { if (TetrisGame.rgen.NextDouble() < rules.StupidFactor) { continue; } } Nomino cloneFor = new Nomino(bg); foreach (var resetblock in cloneFor) { resetblock.Block = new StandardColouredBlock(); } int XOffset = x - bg.X; StoredBoardState BuildState = new StoredBoardState(Source, cloneFor, XOffset, useRotation); if (!BuildState.InvalidState) { yield return(BuildState); } } } }