Skip to content

Commit

Permalink
Merge branch 'AI' into menu-reconfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
thewithz authored Feb 6, 2020
2 parents 1422b27 + 438a840 commit 21ef2ca
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 160 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions OdysseyNow/Assets/Scripts/AI/card1.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using d = CardDirection.Director;

namespace BOT
{
/// <summary>
/// This is basically a copy of PlayerCubeController. It's bad and you shouldn't use any of it.
/// </summary>
public class BOTCubeController : MonoBehaviour
{

private Vector3 newPos;
public GameObject tgt;
static public int lagfactor = 5;
static private float offset = 0;


// Use this for initialization
void Start()
{
}

// Update is called once per frame
void FixedUpdate()
{
if (!d.instance.paused)
{
float tgtx = tgt.transform.position.x;
float tgty = tgt.transform.position.y;

// Goes 1/8 of the distance to the target (hopefully will have some lag)
// Also if the target distance is pretty close, stop moving. Close enough counts in horseshoes, hand grenades, and the Magnavox Odyssey
float oldx = gameObject.transform.position.x;
float destx = (tgtx - oldx) / lagfactor + gameObject.transform.position.x;
if (Mathf.Abs(oldx - destx) < 0.05) destx = oldx;

float oldy = gameObject.transform.position.y;
float desty = (tgty - oldy) / lagfactor + gameObject.transform.position.y;
if (Mathf.Abs(oldy - desty) < 0.05) desty = oldy;
newPos = new Vector3(destx, desty + offset, gameObject.transform.position.z);
gameObject.transform.SetPositionAndRotation(newPos, gameObject.transform.rotation);
}
}

}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using d = CardDirection.Director;

namespace BOT
{
/// <summary>
/// This is basically a copy of PlayerCubeController. It's bad and you shouldn't use any of it.
/// </summary>
public class BOTCubeController : MonoBehaviour
{

private Vector3 newPos;
public GameObject tgt;
static public int lagfactor = 5;
static private float offset = 0;


// Use this for initialization
void Start()
{
}

// Update is called once per frame
void FixedUpdate()
{
if (!d.instance.paused)
{
float tgtx = tgt.transform.position.x;
float tgty = tgt.transform.position.y;

// Goes 1/8 of the distance to the target (hopefully will have some lag)
// Also if the target distance is pretty close, stop moving. Close enough counts in horseshoes, hand grenades, and the Magnavox Odyssey
float oldx = gameObject.transform.position.x;
float destx = (tgtx - oldx) / lagfactor + gameObject.transform.position.x;
if (Mathf.Abs(oldx - destx) < 0.05) destx = oldx;

float oldy = gameObject.transform.position.y;
float desty = (tgty - oldy) / lagfactor + gameObject.transform.position.y;
if (Mathf.Abs(oldy - desty) < 0.05) desty = oldy;
newPos = new Vector3(destx, desty + offset, gameObject.transform.position.z);
gameObject.transform.SetPositionAndRotation(newPos, gameObject.transform.rotation);
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace BOT
{
/// <summary>
/// This is from the original AI demo. It is bad and you should not use it.
/// </summary>
public class BOTEngTargetControl : MonoBehaviour
{

public float startx, starty;
static float targetY;
public float speed = 10;
public GameObject opponent;
public GameObject ball;

void Start()
{
gameObject.transform.position = new Vector3(startx, starty, 0);
targetY = 0;
StartCoroutine(RandomEng());
}

void Update()
{
//smoothly move the target
if (targetY - gameObject.transform.position.y > 0.1)
{
gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + speed * Time.deltaTime, 0);
}
else if (targetY - gameObject.transform.position.y < -0.1)
{
gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y - speed * Time.deltaTime, 0);
}
}

//Randomly select a spot every 0.2 sec
IEnumerator RandomEng()
{
while (true)
{
//no ridiculous movement
targetY = Random.Range(-8, 8);
yield return new WaitForSeconds(0.4f);
}
}

}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace BOT
{
/// <summary>
/// This is from the original AI demo. It is bad and you should not use it.
/// </summary>
public class BOTEngTargetControl : MonoBehaviour
{

public float startx, starty;
static float targetY;
public float speed = 10;
public GameObject opponent;
public GameObject ball;

void Start()
{
gameObject.transform.position = new Vector3(startx, starty, 0);
targetY = 0;
StartCoroutine(RandomEng());
}

void Update()
{
//smoothly move the target
if (targetY - gameObject.transform.position.y > 0.1)
{
gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + speed * Time.deltaTime, 0);
}
else if (targetY - gameObject.transform.position.y < -0.1)
{
gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y - speed * Time.deltaTime, 0);
}
}

//Randomly select a spot every 0.2 sec
IEnumerator RandomEng()
{
while (true)
{
//no ridiculous movement
targetY = Random.Range(-8, 8);
yield return new WaitForSeconds(0.4f);
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace BOT
{
/// <summary>
/// This is from the original AI demo. It is bad and you should not use it.
/// If one is to make an AI to play one of these games, you should ONLY need a script like this that controls the player target, since the player target (and english target) are the only things players impact.
/// We need at least one target controller script for every game AI.
/// </summary>
public class BOTTargetControl : MonoBehaviour
{
public float startx, starty;
public GameObject ball;
private float randomy, lagf;

void Start()
{
gameObject.transform.position = new Vector3(startx, starty, 0);
StartCoroutine(RandomPos()); StartCoroutine(RandomSpeed());
}

void Update()
{
float y;
if (ball.transform.position.x > 0)
{
//Always follows the ball(LagFactor reduced to allow the AI catch up to the ball)
BOTCubeController.lagfactor = (int)lagf;
y = ball.transform.position.y;
gameObject.transform.position = new Vector3(gameObject.transform.position.x, y, gameObject.transform.position.z);
}
else
{
BOTCubeController.lagfactor = 20;
y = randomy;
gameObject.transform.position = new Vector3(gameObject.transform.position.x, y, gameObject.transform.position.z);
}
}

IEnumerator RandomSpeed()
{
while (true)
{
lagf = Random.Range(4, 10);
yield return new WaitForSeconds(0.5f);
}
}

IEnumerator RandomPos()
{
while (true)
{
randomy = Random.Range(-4, 4);
yield return new WaitForSeconds(0.5f);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace BOT
{
/// <summary>
/// This is from the original AI demo. It is bad and you should not use it.
/// If one is to make an AI to play one of these games, you should ONLY need a script like this that controls the player target, since the player target (and english target) are the only things players impact.
/// We need at least one target controller script for every game AI.
/// </summary>
public class BOTTargetControl : MonoBehaviour
{
public float startx, starty;
public GameObject ball;
private float randomy, lagf;

void Start()
{
gameObject.transform.position = new Vector3(startx, starty, 0);
StartCoroutine(RandomPos()); StartCoroutine(RandomSpeed());
}

void Update()
{
float y;
if (ball.transform.position.x > 0)
{
//Always follows the ball(LagFactor reduced to allow the AI catch up to the ball)
BOTCubeController.lagfactor = (int)lagf;
y = ball.transform.position.y;
gameObject.transform.position = new Vector3(gameObject.transform.position.x, y, gameObject.transform.position.z);
}
else
{
BOTCubeController.lagfactor = 20;
y = randomy;
gameObject.transform.position = new Vector3(gameObject.transform.position.x, y, gameObject.transform.position.z);
}
}

IEnumerator RandomSpeed()
{
while (true)
{
lagf = Random.Range(4, 10);
yield return new WaitForSeconds(0.5f);
}
}

IEnumerator RandomPos()
{
while (true)
{
randomy = Random.Range(-4, 4);
yield return new WaitForSeconds(0.5f);
}
}
}
}
8 changes: 8 additions & 0 deletions OdysseyNow/Assets/Scripts/AI/card4.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion OdysseyNow/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2019.3.0f6
m_EditorVersionWithRevision: 2019.3.0f6 (27ab2135bccf)
m_EditorVersionWithRevision: 2019.3.0f6 (27ab2135bccf)

0 comments on commit 21ef2ca

Please sign in to comment.