Instructions Using the provided Bomber Belts Unity Project, write your own AI Script for the character to play the game. Your script will be used on a character while another classmate’s script will...

1 answer below »


Instructions

Using the provided Bomber Belts Unity Project, write your own AI Script for the character to play the game. Your script will be used on a character while another classmate’s script will be used on the opposing character. Please refer to the information below on how and where to write the code.


1. Download the Bomber Belts 2014 Project from Moodle


2. Open the Scene named Menu inside of the Assets folder


3. Locate the
AI_Template.cs
file inside of the Assets / Resources / AI Scripts folder


a. This is the script you will modify to create your AI algorithm


b. Refer to the information below on available functions to call


c. You may also use the
AI_Sample.cs
script to see an example implementation



d.

Change the name of the script to
AIScript_YourName.cs

(it will be AIScript_JillPartin.cs)




i.

You will also need to change the class name (It will be ITCS3153-080)



4.

Do NOT make any modifications to any other scripts in the project



a.

Any modifications to the speed of the bombs or players, or any adjustments to the game that grants an unfair advantage to a player will automatically result in a zero for this assignment.


5. To test your script, simply run the Menu screen and select your script.



Coding Framework Information

All of the functionality for moving your character, sending bombs, and positional/state information of the belts and bombs have been written for you inside other scripts. You can access those functions by using the
mainScript
variable that is already declared and initialized for you inside of the
AI_Template.cs
file. Below is a complete list of functions.


















































void
moveUp()



Moves the player up. The player will continue to move up until otherwise instructed.



void
moveDown()



Moves the player down. The player will continue to move down until otherwise instructed.



void
push()



Attempts to push the closest button. If the character is too far from the button, the button is already engaged, or is on cooldown, nothing will happen.



float
getCharacterLocation()



Returns the position of the character as a float



float
getOpponentLocation()



Returns the position of the opposing character as a float



float[]
getButtonLocations()



Returns an array of floats for representing the position of each button on your side



float[]
getButtonCooldowns()



Returns an array of floats representing the time remaining before each button may be pressed again.



bool[] getBeltDirection()



Returns an array of Boolean values that corresponds to whether or not the buttons on your side of the board have been engaged. True means the belt/button is engaged and the bomb is moving towards your opponent.



float[] getBombDistances()



Returns an array of float values that represent the distance each bomb is from its corresponding button on your side



float getPlayerSpeed()



Returns the speed at which the characters move



float getBombSpeed()



Returns the speed at which the bombs move











Submission Information

Make sure that you’ve changed the name of the script to
AIScript_YourName.cs and that you’ve also changed the class name to match the file name. Upload your completed AI script to Moodle.






A Few Points


· Whenever a button is pressed, that belt becomes disabled for 1.0 second. Neither player may press a button on that belt until the second has elapsed. Example: the blue player presses the button on belt 1. Both the blue player’s button 1 and the red player’s button 1 become disabled for 1.0 second.


· You can access the list of each bomb’s current cooldown by calling
getButtonCooldowns().


· Calling moveUp()at the very top will have no effect. This is likewise true for moveDown()at the bottom.


· Make sure your script has elements of AI. Simply copying what the opponent is doing (i.e., following) or doing the same time every time regardless of what environmental percepts dictate is not AI.


(Y (you are not allowed to change anything in the below program above the part marked //Your AI code goes here. ) (except to change the name and class)

using UnityEngine;using System.Collections;
public class AI_Template : MonoBehaviour {

public CharacterScript mainScript;

public float[] bombSpeeds; public float[] buttonCooldowns; public float playerSpeed; public int[] beltDirections; public float[] buttonLocations;
// Use this for initializationvoid Start () { mainScript = GetComponentCharacterScript>();

if (mainScript == null) { print("No CharacterScript found on " + gameObject.name); this.enabled = false; }

buttonLocations = mainScript.getButtonLocations();

playerSpeed = mainScript.getPlayerSpeed();}
// Update is called once per framevoid Update () {

buttonCooldowns = mainScript.getButtonCooldowns(); beltDirections = mainScript.getBeltDirections();

//Your AI code goes here}}




Answered Same DayJun 19, 2021

Answer To: Instructions Using the provided Bomber Belts Unity Project, write your own AI Script for the...

David answered on Jun 22 2021
156 Votes
using UnityEngine;
using System.Threading;
public class AIScript_JillPartin : MonoBehaviour
{
public CharacterScript mainScript;
public float[] bombSpeeds;
public float[] buttonCooldowns;
pub
lic float playerSpeed;
public int[] beltDirections;
public float[] buttonLocations;
// private variables
private float[] bombDistances;
private float playerLocation;
private float enemyLocation;
private int playerLives = 8, enemyLives = 8;
private const float PADDING = 0.1f;
private const int NUM_BUTTONS = 8;
private const int MOVE = 1, PUSH = 2, THINK = 3;
private int action = PUSH;

private float[] buttonVals;
private int nextStep = 0;
private int lastStep = -1;
private int newBombs = 0;
private int oldSpookyBombs = 0;
private float stressedBot = 1f;
private Thread thread;
// Use this for initialization
void Start()
{
mainScript = GetComponent();
if (mainScript == null)
{
print("No CharacterScript found on " + gameObject.name);
this.enabled = false;
}
buttonLocations = mainScript.getButtonLocations();
playerSpeed = mainScript.getPlayerSpeed();
buttonVals = new float[NUM_BUTTONS];
playerLocation = mainScript.getCharacterLocation();
enemyLocation = mainScript.getOpponentLocation();
thread = new Thread(new ThreadStart(findPath));
thread.Start();
}
// Update is called once per frame
void Update()
{
// Updating Values
buttonCooldowns = mainScript.getButtonCooldowns();
beltDirections = mainScript.getBeltDirections();
bombSpeeds = mainScript.getBombSpeeds();
playerSpeed = mainScript.getPlayerSpeed();
bombDistances = mainScript.getBombDistances();
playerLocation = mainScript.getCharacterLocation();
enemyLocation = mainScript.getOpponentLocation();

Log("" + thread.IsAlive);
if (thread.IsAlive == false)
{
thread = new...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here