Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class AIBrain : MonoBehaviour
  6. {
  7. private WinCondition winCondition;
  8.  
  9. public GameObject[] allSlotsGO = new GameObject[8]; //all slots on game board
  10. public bool[] isSlotsUnused = new bool[8]; //which slots on the game board have not been placed on
  11. int turnCounter = 1;
  12.  
  13. void Awake()
  14. {
  15. winCondition = gameObject.GetComponent<WinCondition> ();
  16. }
  17.  
  18. void Start()
  19. {
  20. Setup();
  21. }
  22.  
  23. void Setup()
  24. {
  25. /*for(int i = 0; i < isSlotsUnused.length; i++)
  26. {
  27. isSlotsUnused[i] = true;
  28. }*/
  29. }
  30.  
  31. void AIMove()
  32. {
  33. //find out what turn its on, assume it always starts on turn 1, because it does..
  34. switch(turnCounter)
  35. {
  36. case 1:
  37. MoveOne();
  38. break;
  39. case 2:
  40. MoveTwo();
  41. break;
  42. case 3:
  43. MoveThree();
  44. break;
  45. case 4:
  46. MoveFour();
  47. break;
  48. case 5:
  49. MoveFive();
  50. break;
  51. }
  52. //increment counter
  53. turnCounter += 1;
  54. }
  55.  
  56. void MoveOne()
  57. {
  58. bool hasPlayed = false;
  59. int playAttempt;
  60.  
  61. while(hasPlayed == false)
  62. {
  63. playAttempt = Random.Range(0,8); //randomly move 0-8
  64. if (winCondition.xMarker[playAttempt] == false && winCondition.oMarker[playAttempt] == false)
  65. hasPlayed == true;
  66. }
  67.  
  68. //place on allSlotsGO[playAttempt] //lets say that move was pos1
  69. //change isSlotsUnused[playAttempt] to false //place 1
  70. }
  71.  
  72. void MoveTwo()
  73. {
  74. bool hasPlayed = false;
  75. int playAttempt;
  76.  
  77. while(hasPlayed == false)
  78. {
  79. playAttempt = Random.Range(0,8); //randomly place 0-6, lets say player moves on pos2
  80. if (isSlotsUnused [playAttempt] == true)
  81. hasPlayed == true;
  82. }
  83.  
  84. //place on allSlotsGO[playAttempt] //lets say that move was pos3
  85. //change isSlotsUnused[playAttempt] to false //[place 3]
  86.  
  87. }
  88.  
  89. void MoveThree()
  90. {
  91. bool hasPlayed = false;
  92. int playAttempt;
  93.  
  94. while(hasPlayed == false)
  95. {
  96. playAttempt = Random.Range(0,8); //randomly place 0-6, lets say player moves on pos4
  97. if (isSlotsUnused [playAttempt] == true)
  98. hasPlayed == true;
  99. }
  100.  
  101. //place on allSlotsGO[playAttempt] //lets say that move was pos5
  102. //change isSlotsUnused[playAttempt] to false //[place 5]
  103.  
  104. }
  105.  
  106. void MoveFour()
  107. {
  108. bool hasPlayed = false;
  109. int playAttempt;
  110.  
  111. while(hasPlayed == false)
  112. {
  113. playAttempt = Random.Range(0,8); //randomly place 0-6, lets say player moves on pos6
  114. if (isSlotsUnused [playAttempt] == true)
  115. hasPlayed == true;
  116. }
  117.  
  118. //place on allSlotsGO[playAttempt] //lets say that move was pos7
  119. //change isSlotsUnused[playAttempt] to false //[place 7]
  120.  
  121. }
  122.  
  123. void MoveFive()
  124. {
  125. bool hasPlayed = false;
  126. int playAttempt;
  127.  
  128. while(hasPlayed == false)
  129. {
  130. playAttempt = Random.Range(0,8); //randomly place 0-6, lets say player moves on pos8
  131. if (isSlotsUnused [playAttempt] == true)
  132. hasPlayed == true;
  133. }
  134.  
  135. //place on allSlotsGO[playAttempt] //lets say that move was pos9
  136. //change isSlotsUnused[playAttempt] to false //[place 9]
  137.  
  138. }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement