override public NextMovementChoice Execute() { NextMovementChoice nextChoice = new NextMovementChoice(); nextChoice.NextMove = NextMovementChoice.NextMoveType.MOVE_WEST; return(nextChoice); }
override public NextMovementChoice Execute() { NextMovementChoice nextChoice = new NextMovementChoice(); nextChoice.NextMove = NextMovementChoice.NextMoveType.NONE; //return move in no direction return(nextChoice); }
override public NextMovementChoice Execute() { NextMovementChoice nextChoice = new NextMovementChoice(); nextChoice.NextMove = NextMovementChoice.NextMoveType.MOVE_TYPE_MAX; //return highes priority to tell game game over return(nextChoice); }
override public NextMovementChoice Execute() { NextMovementChoice nextChoice = new NextMovementChoice(); nextChoice.NextMove = NextMovementChoice.NextMoveType.MOVE_EAST; //return move in proper direction return(nextChoice); }
// Use this for initialization void Start() { ruleAI = new RuleFrameWork(); mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); worldState = mainCamera.GetComponent <WorldData>(); lastMove = new NextMovementChoice(); nextMove = new NextMovementChoice(); nextMove.NextMove = NextMovementChoice.NextMoveType.MOVE_NORTH; //The world keeps track of the character's data worldState.CharAI1 = this; }
override public NextMovementChoice Execute() { //randomy choose a open but visited direction NextMovementChoice nextChoice = new NextMovementChoice(); Random rand = new Random(); int r = rand.Next(0, backTrackMoves.Count); nextChoice.NextMove = backTrackMoves[r]; backTrackMoves.Clear(); return(nextChoice); }
public void DetermineOpenMoves(BoardSpace charSpace) { NextMovementChoice charNextMove = CharAI1.NextMove; InitPossibleMoves(); //TODO Check for free positions //Check for open moves on the board and set the appropriate flags topFree = isTopNeighbourOpen(charSpace, ref topVisited, ref topFood, ref topPowerUp); bottomFree = isBottomNeighbourOpen(charSpace, ref bottomVisited, ref bottomFood, ref bottomPowerUp); rightFree = isRightNeighbourOpen(charSpace, ref rightVisited, ref rightFood, ref rightPowerUp); leftFree = isLeftNeighbourOpen(charSpace, ref leftVisited, ref leftFood, ref leftPowerUp); //The world stores all the open moves for the rule framework }
public NextMovementChoice RunAI_Evalute(WorldData worldState) { RulePriorityType highestRulePriority = RulePriorityType.NO_INIT; Rule highestMatchingRule = null; NextMovementChoice bestMove = null; worldState.DetermineOpenMoves(worldState.PlayerCurrentSpace); //Check to see if any rules match the worldState, keep track of the one with highest priority foreach (Rule rule in Rules) { if (rule.Match(worldState)) { if (rule.rulePriority > highestRulePriority) { //highest priority aways take precident highestRulePriority = rule.rulePriority; highestMatchingRule = rule; } else if (rule.rulePriority == highestRulePriority) { //if rule is equla priority randomly chose to keep it = 0 or skip it = 1) var r = new System.Random(); int decider = r.Next(0, 2); if (decider == 0) { highestRulePriority = rule.rulePriority; highestMatchingRule = rule; } } } } //Execute the rule with the highest priority if (highestMatchingRule != null) { //if there is async matching rule set best move to that bestMove = highestMatchingRule.Execute(); } //return the best rule return(bestMove); }
//private void Update() //{ // Forward(); // transform.Translate(new Vector3(dx, dy, dz)); //} // Update is called once per frame void FixedUpdate() { if (worldState.gameOver == true) { return; } if (worldState.PlayerCurrentSpace) { Vector3 destPosition = worldState.PlayerCurrentSpace.transform.position; destPosition.y = 0; Vector3 currentPosition = this.transform.position; currentPosition.y = 0; float dist = Vector3.Distance(currentPosition, destPosition); if (dist <= 0.25f) { Debug.Log("Reached position, get new position"); lastMove.NextMove = nextMove.NextMove; //keep track of the last move worldState.LastMove = lastMove.NextMove; //TODO: GET the decision from the AI on what to do next nextMove = ruleAI.RunAI_Evalute(worldState); Debug.Log(nextMove.NextMove.ToString()); worldState.PlayerCurrentSpace = null; } } //check the response of the rule and apply the correct movement method switch (nextMove.NextMove) { case NextMovementChoice.NextMoveType.MOVE_NORTH: Forward(); break; case NextMovementChoice.NextMoveType.MOVE_EAST: Right(); break; case NextMovementChoice.NextMoveType.MOVE_SOUTH: Backward(); break; case NextMovementChoice.NextMoveType.MOVE_WEST: Left(); break; case NextMovementChoice.NextMoveType.MOVE_TYPE_MAX: worldState.gameOver = true; break; default: Stop(); break; } //Move direction determined by AI transform.Translate(new Vector3(dx, dy, dz)); }