V
V
Vitaly Gyrdasov2015-06-11 18:55:17
C++ / C#
Vitaly Gyrdasov, 2015-06-11 18:55:17

UNITY How to make a primitive AI in this implementation of the tic-tac-toe game?

Good day/evening/night!
I "sculpt" the game tic-tac-toe on Unity. Almost without experience, several options came to mind, I settled on the current one (see below). Now I have reached the implementation of the computer game, I did everything without arrays, and something I find it difficult. I ask for help, not a ready-made solution, but a direction (so that I can understand and not ask such questions again).
Now about the implementation:
There is a camera on the stage, a 3x3 grid and 9 empty objects in places where a cross or a zero is placed. The GameProcess.cs script is attached to the camera, and onClick.cs to the empty objects.
GameProcess.cs

public GameObject cross, zero;
  public enum cell {EMPTY, CROSS, ZERO};
  public cell turn;
  public int i = 0;

  public void SpawnNew(GameObject obj)
  {
    if (turn == cell.CROSS) {
      Instantiate (cross, obj.transform.position, Quaternion.identity); 
      turn = cell.ZERO;
      i++;
    } else {
      Instantiate (zero, obj.transform.position, Quaternion.identity);
      turn = cell.CROSS;
      i++;
    }

    Destroy (obj.gameObject);
  }
}

onClick.cs
public GameObject Camera;
  public GameProcess Script;

  void Awake() {
    Script = Camera.GetComponent<GameProcess> (); 
  }

  void OnMouseDown() {
    Script.SpawnNew (this.gameObject); 
  }	
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Insider22, 2015-06-17
@mrdemkin

tic-tac-toe is a solved game, it doesn't need AI. it is the same as rock paper scissors.
If the move (strategy) is A, then the answer is always A1. another answer would be wrong.

M
myfirepukan, 2015-06-11
@myfirepukan

If two signs of the enemy are in adjacent cells, then ... you need to strain and put the sign so as not to allow the line. In this case, you can simply go through the options and tell the AI ​​exactly what to put where if there is such and such a combination. Alas, I don't know C#, I can't code

S
Sumor, 2015-06-11
@Sumor

Martin Gardner Self-made self-learning machine...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question