コード例 #1
0
        public FieldLineActionGameState(GameplayGameState _BaseState, int[] ClearRows, IEnumerable <Action> pAfterClearActions) : base(_BaseState)
        {
            PlayField = _BaseState.PlayField;
            //prep the ClearRowInfo. take the row information from the state at the specified row indices, and plop them into ClearRowInfo at those keys.
            var ContentData = _BaseState.PlayField.Contents;

            ClearRowInfo = new Dictionary <int, NominoBlock[]>();
            foreach (var index in ClearRows)
            {
                NominoBlock[] thisrow = new NominoBlock[ContentData[index].Length];
                Array.Copy(ContentData[index], thisrow, ContentData[index].Length);
                //add to Dictionary.
                ClearRowInfo.Add(index, thisrow);
                //wipe out the original row to all be nulls.
                for (int i = 0; i < ContentData[index].Length; i++)
                {
                    ContentData[index][i] = null;
                }
            }



            AfterClear = pAfterClearActions;
            // RowNumbers = ClearRows;
        }
コード例 #2
0
 public override void Render(IStateOwner pOwner, Graphics pRenderTarget, NominoBlock Source, TetrisBlockDrawParameters Element)
 {
     if (Source is ImageBlock)
     {
         this.Render(pOwner, pRenderTarget, (ImageBlock)Source, Element);
     }
 }
コード例 #3
0
 public NominoElement(NominoElement clonesource)
 {
     RotationModulo = clonesource.RotationModulo;
     Positions      = new Point[clonesource.Positions.Length];
     clonesource.Positions.CopyTo(Positions, 0);
     Block          = clonesource.Block;
     Block.Rotation = clonesource.RotationModulo;
 }
コード例 #4
0
ファイル: TetrisField.cs プロジェクト: BCProgramming/BASeTris
 public void Reset()
 {
     FieldContents = new NominoBlock[RowCount][];
     for (int row = 0; row < RowCount; row++)
     {
         FieldContents[row] = new NominoBlock[ColCount];
     }
     ActiveBlockGroups.Clear();
 }
コード例 #5
0
        public NominoElement(Point[] RotationPoints, NominoBlock pBlock)
        {
            if (RotationPoints.Length == 0)
            {
                throw new ArgumentException("RotationPoints");
            }

            Positions = RotationPoints;
            Block     = pBlock;
        }
コード例 #6
0
        //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.
        }
コード例 #7
0
ファイル: TetrisAI.cs プロジェクト: BCProgramming/BASeTris
        public static NominoBlock[][] DuplicateField(NominoBlock[][] Source)
        {
            NominoBlock[][] Copied = new NominoBlock[Source.Length][];
            for (int r = 0; r < Source.Length; r++)
            {
                NominoBlock[] row = Source[r];
                Copied[r] = new NominoBlock[row.Length];
                for (int c = 0; c < row.Length; c++)
                {
                    Copied[r][c] = row[c];
                }
            }

            return(Copied);
        }
コード例 #8
0
        public static IEnumerable <NominoElement> GetNominoEntries(Point[][] Source, Func <int, NominoBlock> BuildBlock = null)
        {
            if (BuildBlock == null)
            {
                BuildBlock = (i) => new StandardColouredBlock();
            }
            int index = 0;

            foreach (Point[] loopposdata in Source)
            {
                NominoBlock CreateBlock = BuildBlock(index);
                yield return(new NominoElement(loopposdata, CreateBlock));

                index++;
            }
        }
コード例 #9
0
        public static IEnumerable <NominoElement> GetNominoEntries(Point[] Source, Size AreaSize, Func <int, NominoBlock> BuildBlock = null)
        {
            if (BuildBlock == null)
            {
                BuildBlock = (i) => new StandardColouredBlock();
            }
            //assumes a "single" set of blocks, we rotate it with the NominoElement Constructor for the needed rotation points.
            int index = 0;

            foreach (Point BlockPos in Source)
            {
                NominoBlock CreateBlock = BuildBlock(index);
                var         ne          = new NominoElement(BlockPos, AreaSize, CreateBlock);
                yield return(ne);

                index++;
            }
        }
コード例 #10
0
        protected override void OnKeyDown(KeyboardKeyEventArgs e)
        {
            _Present.IgnoreController = true;
            if (e.Key == Key.G)
            {
                if (_Present.Game.CurrentState is GameplayGameState)
                {
                    GameplayGameState gs      = _Present.Game.CurrentState as GameplayGameState;
                    NominoBlock[][]   inserts = new NominoBlock[4][];
                    for (int i = 0; i < inserts.Length; i++)
                    {
                        inserts[i] = new NominoBlock[gs.PlayField.ColCount];
                        for (int c = 1; c < inserts[i].Length; c++)
                        {
                            inserts[i][c] = new StandardColouredBlock()
                            {
                                BlockColor = Color.Red, DisplayStyle = StandardColouredBlock.BlockStyle.Style_CloudBevel
                            };
                        }
                    }

                    InsertBlockRowsActionGameState irs = new InsertBlockRowsActionGameState(gs, 0, inserts, Enumerable.Empty <Action>());
                    CurrentState = irs;
                }
            }
            else if (e.Key == Key.C)
            {
                if (e.Shift && e.Control)
                {
                    EnterCheatState cheatstate = new EnterCheatState(CurrentState, _Present.Game, 64);
                    CurrentState = cheatstate;
                }
            }

            Debug.Print("Button pressed:" + e.Key);
            var translated = _Present.TranslateKey(e.Key);

            if (translated != null)
            {
                _Present.Game.HandleGameKey(this, translated.Value, TetrisGame.KeyInputSource.Input_HID);
                _Present.GameKeyDown(translated.Value);
            }
        }
コード例 #11
0
        public static int CountColumnHoles(NominoBlock[][] _BoardState, int column)
        {
            int FoundSinceFilled = 0;
            int FoundTotal       = 0;

            for (int i = _BoardState.Length - 1; i > 0; i--)
            {
                NominoBlock ThisBlock = _BoardState[i][column];
                if (ThisBlock == null)
                {
                    FoundSinceFilled++;
                }
                else
                {
                    FoundTotal      += FoundSinceFilled;
                    FoundSinceFilled = 0;
                }
            }

            return(FoundTotal);
        }
コード例 #12
0
 public bool HasBlock(NominoBlock block)
 {
     return(BlockDataLookup.ContainsKey(block));
 }
コード例 #13
0
 public NominoElement FindEntry(NominoBlock findBlock)
 {
     return(BlockDataLookup[findBlock]);
 }
コード例 #14
0
 public void RemoveBlock(NominoBlock tb)
 {
     BlockData.Remove(FindEntry(tb));
     //_DataLookup = null;
 }
コード例 #15
0
 public NominoElement(Point Point, Size AreaSize, NominoBlock pBlock)
 {
     Positions = GetRotations(Point, AreaSize);
     Block     = pBlock;
 }
コード例 #16
0
        public void AddBlock(Point[] RotationPoints, NominoBlock tb)
        {
            NominoElement bge = new NominoElement(RotationPoints, tb);

            AddBlock(bge);
        }
コード例 #17
0
 public BlockClearData(NominoBlock pBlock, params BCPoint[] pVector)
 {
     Block            = pBlock;
     DirectionVectors = pVector;
 }
コード例 #18
0
ファイル: NominoTheme.cs プロジェクト: BCProgramming/BASeTris
 public virtual bool IsAnimated(NominoBlock block)
 {
     return(false);
 }
コード例 #19
0
 public BlockClearData(NominoBlock pBlock) : this(pBlock, BCPoint.Empty)
 {
 }