Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class AIBrain : MonoBehaviour
- {
- private WinCondition winCondition;
- public GameObject[] allSlotsGO = new GameObject[8]; //all slots on game board
- public bool[] isSlotsUnused = new bool[8]; //which slots on the game board have not been placed on
- int turnCounter = 1;
- void Awake()
- {
- winCondition = gameObject.GetComponent<WinCondition> ();
- }
- void Start()
- {
- Setup();
- }
- void Setup()
- {
- /*for(int i = 0; i < isSlotsUnused.length; i++)
- {
- isSlotsUnused[i] = true;
- }*/
- }
- void AIMove()
- {
- //find out what turn its on, assume it always starts on turn 1, because it does..
- switch(turnCounter)
- {
- case 1:
- MoveOne();
- break;
- case 2:
- MoveTwo();
- break;
- case 3:
- MoveThree();
- break;
- case 4:
- MoveFour();
- break;
- case 5:
- MoveFive();
- break;
- }
- //increment counter
- turnCounter += 1;
- }
- void MoveOne()
- {
- bool hasPlayed = false;
- int playAttempt;
- while(hasPlayed == false)
- {
- playAttempt = Random.Range(0,8); //randomly move 0-8
- if (winCondition.xMarker[playAttempt] == false && winCondition.oMarker[playAttempt] == false)
- hasPlayed == true;
- }
- //place on allSlotsGO[playAttempt] //lets say that move was pos1
- //change isSlotsUnused[playAttempt] to false //place 1
- }
- void MoveTwo()
- {
- bool hasPlayed = false;
- int playAttempt;
- while(hasPlayed == false)
- {
- playAttempt = Random.Range(0,8); //randomly place 0-6, lets say player moves on pos2
- if (isSlotsUnused [playAttempt] == true)
- hasPlayed == true;
- }
- //place on allSlotsGO[playAttempt] //lets say that move was pos3
- //change isSlotsUnused[playAttempt] to false //[place 3]
- }
- void MoveThree()
- {
- bool hasPlayed = false;
- int playAttempt;
- while(hasPlayed == false)
- {
- playAttempt = Random.Range(0,8); //randomly place 0-6, lets say player moves on pos4
- if (isSlotsUnused [playAttempt] == true)
- hasPlayed == true;
- }
- //place on allSlotsGO[playAttempt] //lets say that move was pos5
- //change isSlotsUnused[playAttempt] to false //[place 5]
- }
- void MoveFour()
- {
- bool hasPlayed = false;
- int playAttempt;
- while(hasPlayed == false)
- {
- playAttempt = Random.Range(0,8); //randomly place 0-6, lets say player moves on pos6
- if (isSlotsUnused [playAttempt] == true)
- hasPlayed == true;
- }
- //place on allSlotsGO[playAttempt] //lets say that move was pos7
- //change isSlotsUnused[playAttempt] to false //[place 7]
- }
- void MoveFive()
- {
- bool hasPlayed = false;
- int playAttempt;
- while(hasPlayed == false)
- {
- playAttempt = Random.Range(0,8); //randomly place 0-6, lets say player moves on pos8
- if (isSlotsUnused [playAttempt] == true)
- hasPlayed == true;
- }
- //place on allSlotsGO[playAttempt] //lets say that move was pos9
- //change isSlotsUnused[playAttempt] to false //[place 9]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement