Example #1
0
        public static string GetMessageFromState(AlgorithmState set_from)
        {
            string complete_message;

            complete_message = "";
            if (!program_launch_message)
            {
                program_launch_message = true;
                complete_message       = "The program has been launched.\nBender's starting position is (";
                complete_message      += (set_from.board_data.bender.x_coordinate + 1).ToString() + ", " + (set_from.board_data.bender.y_coordinate + 1).ToString() + ").";
            }
            else if (!AlgorithmState.algorithm_started)
            {
                complete_message = "The board was reset. Progress has been erased.";
            }

            //Starting data
            else if (set_from.GetStepNumber() == 0)
            {
                complete_message  = "A new episode has been created.\n";
                complete_message += "Starting turn [Episode: " + set_from.GetEpisodeNumber().ToString();
                complete_message += ", Step: " + set_from.GetStepNumber().ToString() + "]";
                complete_message += " at position (" + (set_from.board_data.bender.x_coordinate + 1).ToString();
                complete_message += ", " + (set_from.board_data.bender.y_coordinate + 1).ToString() + ").";
                complete_message += System.Environment.NewLine + "Bender's initial perception is:";
                complete_message += System.Environment.NewLine + set_from.bender_perception_ending.ToString() + ".";
            }
            else
            {
                //"Episode #, Step # beginning."
                string starting_data = "Starting turn [Episode: " + set_from.GetEpisodeNumber().ToString() + ", Step: " + set_from.GetStepNumber().ToString() + "]";
                starting_data += " at position (" + (set_from.location_initial[0] + 1).ToString() + ", " + (set_from.location_initial[1] + 1).ToString() + ").";

                string initial_percept_data = "Bender's initial perception is: " + System.Environment.NewLine;
                initial_percept_data += set_from.bender_perception_starting.ToString();

                string move_being_applied_data = "";

                if (set_from.live_qmatrix.randomly_moved)
                {
                    move_being_applied_data += "A the move was randomly generated." + System.Environment.NewLine;
                }
                else
                {
                    move_being_applied_data += "The move was greedily chosen." + System.Environment.NewLine;
                }

                if (set_from.move_this_step == Move.grab())
                {
                    move_being_applied_data += "A [Grab] was attempted.";
                }
                else
                {
                    move_being_applied_data += "A [" + set_from.move_this_step.long_name + "] was attempted.";
                }

                //moveresult
                string moveresult_data = "The result of the move was [" + set_from.result_this_step.result_data + "].";

                //The reward from this action was:
                string math_sign = "+";
                if (set_from.obtained_reward < 0)
                {
                    math_sign = "";
                }
                string reward_data = "The reward for this action was: [" + math_sign + set_from.obtained_reward.ToString() + "]";
                //reward_data + = ", applied to state ";
                //Add bender perception data in his new location here

                //"Bender's position is:
                string new_position_data = "The resulting position was (" + (set_from.location_result[0] + 1).ToString();
                new_position_data += ", " + ((set_from.location_result[1]) + 1).ToString() + ").";

                //New percept
                string new_percept_data = "The percept at the new location is: " + System.Environment.NewLine + set_from.bender_perception_ending.ToString() + ".";

                //"The calculation used on the q matrix was:"
                string qmatrix_adjustment_data = "No qmatrix entry was made.";
                if (set_from.live_qmatrix.did_we_update)
                {
                    qmatrix_adjustment_data = "A q-matrix entry was made for this perception.";
                }

                //ending data
                string ending_data = "Move [" + set_from.GetStepNumber().ToString() + "] complete.";

                string newline = System.Environment.NewLine;

                complete_message  = starting_data;
                complete_message += newline + initial_percept_data;
                complete_message += newline + move_being_applied_data;
                complete_message += newline + moveresult_data;
                complete_message += newline + reward_data;
                complete_message += newline + new_position_data;
                complete_message += newline + new_percept_data;
                complete_message += newline + qmatrix_adjustment_data;
                complete_message += newline + ending_data;
            }
            return(complete_message);
        }
Example #2
0
        public StatusMessage(AlgorithmState setFrom)
        {
            string newline = System.Environment.NewLine;

            completeMessage = "";
            if (!programLaunchMessage)
            {
                programLaunchMessage = true;
                completeMessage      = "The program has been launched.\nBender's starting position is (";
                completeMessage     += (setFrom.boardData.GetUnitSquare[UnitType.Bender].x + 1).ToString();
                completeMessage     += ", " + (setFrom.boardData.GetUnitSquare[UnitType.Bender].y + 1).ToString() + ").";
            }
            else if (!AlgorithmManager.algorithmStarted)
            {
                completeMessage = "The board was reset. Progress has been erased.";
            }

            //Starting data
            else if (setFrom.GetStepNumber() == 0)
            {
                completeMessage  = "A new episode has been created.\n";
                completeMessage += "Starting turn [Episode: " + setFrom.GetEpisodeNumber().ToString();
                completeMessage += ", Step: " + setFrom.GetStepNumber().ToString() + "]";
                completeMessage += " at position (" + (setFrom.boardData.GetUnitSquare[UnitType.Bender].x + 1).ToString();
                completeMessage += ", " + (setFrom.boardData.GetUnitSquare[UnitType.Bender].y + 1).ToString() + ").";

                foreach (var unit in UnitType.List)
                {
                    completeMessage += System.Environment.NewLine + unit.unitName + "'s initial perception is:";
                    completeMessage += System.Environment.NewLine + setFrom.GetPerception(unit).ToString() + ".";
                }
            }
            else
            {
                //"Episode #, Step # beginning."
                startingData  = "Starting turn [Episode: " + setFrom.GetEpisodeNumber().ToString() + ", Step: " + setFrom.GetStepNumber().ToString() + "]";
                startingData += " at position (" + (setFrom.locationInitial.x + 1).ToString() + ", " + (setFrom.locationInitial.y + 1).ToString() + ").";

                initialPerceptData  = "Bender's initial perception is: " + System.Environment.NewLine;
                initialPerceptData += setFrom.GetPerception(UnitType.Bender).ToString();

                moveBeingAppliedData = "";

                if (setFrom.liveQmatrix.randomlyMoved)
                {
                    moveBeingAppliedData += "A the move was randomly generated." + System.Environment.NewLine;
                }
                else
                {
                    moveBeingAppliedData += "The move was greedily chosen." + System.Environment.NewLine;
                }

                //if (setFrom.movesThisStep.Count == 0)
                //    moveBeingAppliedData += "No move this turn.";
                if (setFrom.GetUnit(UnitType.Bender).GetMoveThisStep() == Move.Grab)
                {
                    moveBeingAppliedData += "A [Grab] was attempted.";
                }
                else
                {
                    moveBeingAppliedData += "A [" + setFrom.GetUnit(UnitType.Bender).GetMoveThisStep().longName + "] was attempted.";
                }

                //moveresult
                if (setFrom.resultThisStep != null)
                {
                    moveResultData = "The result of the move was [" + setFrom.resultThisStep.result_data + "].";
                }

                //The reward from this action was:
                string math_sign = "+";
                if (setFrom.obtainedReward < 0)
                {
                    math_sign = "";
                }
                rewardData = "The reward for this action was: [" + math_sign + setFrom.obtainedReward.ToString() + "]";
                //reward_data + = ", applied to state ";
                //Add bender perception data in his new location here

                //"Bender's position is:
                newPositionData  = "The resulting position was (" + (setFrom.boardData.GetUnitSquare[UnitType.Bender].x + 1).ToString();
                newPositionData += ", " + (setFrom.boardData.GetUnitSquare[UnitType.Bender].y + 1).ToString() + ").";

                //New percept

                newPerceptData  = "The percept at the new location is: " + System.Environment.NewLine;
                newPerceptData += setFrom.boardData.units[UnitType.Bender].perceptionData.ToString() + ".";

                //"The calculation used on the q matrix was:"

                qmatrixAdjustmentData = "No qmatrix entry was made.";
                if (setFrom.liveQmatrix.didWeUpdate)
                {
                    qmatrixAdjustmentData = "A q-matrix entry was made for this perception.";
                }

                urlData = "Url made a move of " + setFrom.GetUnit(UnitType.Url).GetMoveThisStep().longName + ".";

                if (setFrom.urlRandomlyStopped)
                {
                    urlData += newline + "Url randomly hit his change to stop chasing this turn.";
                }

                if (setFrom.startedChasing)
                {
                    urlData += newline + "Url started chasing Bender.";
                }
                else if (setFrom.boardData.units[UnitType.Url].chasing)
                {
                    urlData += System.Environment.NewLine + "Url is chasing bender.";
                }
                else
                {
                    urlData += System.Environment.NewLine + "Url is wandering randomly.";
                }


                //ending data
                if (setFrom.benderAttacked)
                {
                    endingData += "Bender was attacked this turn, and the board was reset." + newline;
                }
                endingData += "Move [" + setFrom.GetStepNumber().ToString() + "] complete.";

                completeMessage  = startingData;
                completeMessage += newline + initialPerceptData;
                completeMessage += newline + moveBeingAppliedData;
                completeMessage += newline + moveResultData;
                completeMessage += newline + rewardData;
                completeMessage += newline + newPositionData;
                completeMessage += newline + newPerceptData;
                completeMessage += newline + urlData;
                completeMessage += newline + qmatrixAdjustmentData;
                completeMessage += newline + endingData;
            }
        }