Ejemplo n.º 1
0
        public void TrainDictionary(Round[] xnyn, string xn, string yn, int generalMaxSubStringLen)
        {
            charFrequency = new Dictionary <int, Dictionary <string, Dictionary <char, int> > >();
            for (int i = 0; i < xnyn.Count(); i++)
            {
                int maxSubStringLen = new List <int> {
                    xnyn.Count() - i, generalMaxSubStringLen
                }.Min();

                for (int j = 2; j < maxSubStringLen; j++)
                {
                    string xListPreceding = xn.Substring(i, j);
                    char   yOutput        = yn[i + j];

                    charFrequency = FormattingClass.FormatDictionary(charFrequency, j, xListPreceding, yOutput);

                    charFrequency[j][xListPreceding][yOutput] += 1;
                }
            }
        }
Ejemplo n.º 2
0
        private static Move F(Round[] xnyn)
        {
            const int generalMaxSubStringLen      = 4;
            const int generalEnemyMaxSubStringLen = 4;
            var       xn = FormattingClass.FormatXNYN(xnyn)[0];
            var       yn = FormattingClass.FormatXNYN(xnyn)[1];

            UpdateStratSuccess(xnyn);
            ChooseStrategy();

            switch (trailingStrategy)
            {
            case 1:
            {
                // RESPOND ACCORDING TO THEIR RESPONSE
                var modelEnemy = new Model1();
                modelEnemy.TrainDictionary(xnyn, xn, yn, generalMaxSubStringLen);
                modelEnemy.PredictDictionary(xn, generalMaxSubStringLen);

                var  response             = new Response();
                bool isMyDynamiteFinished = xnyn.Count(xiyi => xiyi.GetP1() == Move.D) == 100;
                response.GetBestMoveFromPredictionDictionary(modelEnemy.predictionDictionary, isMyDynamiteFinished);
                response.GetMoveFromString();

                return(response.move);
            }

            case 2:
            {
                // RESPOND ACCORDING TO THEIR RESPONSE
                var modelEnemy = new Model1();
                modelEnemy.TrainDictionary(xnyn, xn, yn, generalMaxSubStringLen);
                modelEnemy.PredictDictionary(xn, generalMaxSubStringLen);

                var  response             = new Response();
                bool isMyDynamiteFinished = xnyn.Count(xiyi => xiyi.GetP1() == Move.D) == 100;
                response.GetBestMoveFromPredictionDictionary(modelEnemy.predictionDictionary, isMyDynamiteFinished);
                response.GetMoveFromString();

                return(response.move);
            }

            case 3:
            {
                // RESPOND ACCORDING TO THEIR RESPONSE
                var modelEnemy = new Model1();
                modelEnemy.TrainDictionary(xnyn, xn, yn, generalMaxSubStringLen);
                modelEnemy.PredictDictionary(xn, generalMaxSubStringLen);

                var  response             = new Response();
                bool isMyDynamiteFinished = xnyn.Count(xiyi => xiyi.GetP1() == Move.D) == 100;
                response.GetBestMoveFromPredictionDictionary(modelEnemy.predictionDictionary, isMyDynamiteFinished);
                response.GetMoveFromString();

                return(response.move);
            }

            case 4:
            {
                // RESPOND ACCORDING TO THEIR PATTERN
                var modelEnemy = new Model1();
                modelEnemy.TrainDictionary(xnyn, yn, yn, generalMaxSubStringLen);
                modelEnemy.PredictDictionary(yn, generalMaxSubStringLen);

                var  response             = new Response();
                bool isMyDynamiteFinished = xnyn.Count(xiyi => xiyi.GetP1() == Move.D) == 100;
                response.GetBestMoveFromPredictionDictionary(modelEnemy.predictionDictionary, isMyDynamiteFinished);
                response.GetMoveFromString();

                return(response.move);
            }

            case 5:
            {
                // RESPOND ACCORDING TO THEIR PATTERN
                var modelEnemy = new Model1();
                modelEnemy.TrainDictionary(xnyn, yn, yn, generalMaxSubStringLen);
                modelEnemy.PredictDictionary(yn, generalMaxSubStringLen);

                var  response             = new Response();
                bool isMyDynamiteFinished = xnyn.Count(xiyi => xiyi.GetP1() == Move.D) == 100;
                response.GetBestMoveFromPredictionDictionary(modelEnemy.predictionDictionary, isMyDynamiteFinished);
                response.GetMoveFromString();

                return(response.move);
            }

            case 6:
            {
                // RESPOND ACCORDING TO THEIR PATTERN
                var modelEnemy = new Model1();
                modelEnemy.TrainDictionary(xnyn, yn, yn, generalMaxSubStringLen);
                modelEnemy.PredictDictionary(yn, generalMaxSubStringLen);

                var  response             = new Response();
                bool isMyDynamiteFinished = xnyn.Count(xiyi => xiyi.GetP1() == Move.D) == 100;
                response.GetBestMoveFromPredictionDictionary(modelEnemy.predictionDictionary, isMyDynamiteFinished);
                response.GetMoveFromString();

                return(response.move);
            }

            case 7:
            {
                // RESPOND ACCORDING TO HOW I WOULD RESPOND TO MYSELF
                var modelMe = new Model1();
                modelMe.TrainDictionary(xnyn, yn, xn, generalEnemyMaxSubStringLen);
                modelMe.PredictDictionary(yn, generalEnemyMaxSubStringLen);

                var  enemyResponse           = new Response();
                bool isEnemyDynamiteFinished = xnyn.Count(xiyi => xiyi.GetP2() == Move.D) == 100;
                enemyResponse.GetBestMoveFromPredictionDictionary(modelMe.predictionDictionary, isEnemyDynamiteFinished);

                var  myResponse           = new Response();
                bool isMyDynamiteFinished = xnyn.Count(xiyi => xiyi.GetP1() == Move.D) == 100;
                myResponse.GetBestMoveFromPrediction(enemyResponse.moveString, isMyDynamiteFinished);
                myResponse.GetMoveFromString();

                return(myResponse.move);
            }

            case 8:
            {
                // RESPOND ACCORDING TO HOW I WOULD RESPOND TO MYSELF
                var modelMe = new Model1();
                modelMe.TrainDictionary(xnyn, yn, xn, generalEnemyMaxSubStringLen);
                modelMe.PredictDictionary(yn, generalEnemyMaxSubStringLen);

                var  enemyResponse           = new Response();
                bool isEnemyDynamiteFinished = xnyn.Count(xiyi => xiyi.GetP2() == Move.D) == 100;
                enemyResponse.GetBestMoveFromPredictionDictionary(modelMe.predictionDictionary, isEnemyDynamiteFinished);

                var  myResponse           = new Response();
                bool isMyDynamiteFinished = xnyn.Count(xiyi => xiyi.GetP1() == Move.D) == 100;
                myResponse.GetBestMoveFromPrediction(enemyResponse.moveString, isMyDynamiteFinished);
                myResponse.GetMoveFromString();

                return(myResponse.move);
            }

            case 9:
            {
                // RESPOND ACCORDING TO HOW I WOULD RESPOND TO MYSELF
                var modelMe = new Model1();
                modelMe.TrainDictionary(xnyn, yn, xn, generalEnemyMaxSubStringLen);
                modelMe.PredictDictionary(yn, generalEnemyMaxSubStringLen);

                var  enemyResponse           = new Response();
                bool isEnemyDynamiteFinished = xnyn.Count(xiyi => xiyi.GetP2() == Move.D) == 100;
                enemyResponse.GetBestMoveFromPredictionDictionary(modelMe.predictionDictionary, isEnemyDynamiteFinished);

                var  myResponse           = new Response();
                bool isMyDynamiteFinished = xnyn.Count(xiyi => xiyi.GetP1() == Move.D) == 100;
                myResponse.GetBestMoveFromPrediction(enemyResponse.moveString, isMyDynamiteFinished);
                myResponse.GetMoveFromString();

                return(myResponse.move);
            }

            case 10:
            {
                return(PseudoRandomMove.GetPseudoRandomMove(xnyn));
            }

            default:
                return(Move.D);
            }
        }