Answer the question
In order to leave comments, you need to log in
Can't make tic-tac-toe medium and hard difficulty levels?
I can't make two difficulty levels for tic-tac-toe. I made an easy one with the help of a random house that selects cells and checks if there is a sign there and sets it depending on the choice of the player's sign.
Here is the easy code:
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.UI;
public class EasyBot : MonoBehaviour
{
public Text[] tbs;
public float timerX = 1f;
public float timerO = 1f;
void Update()
{
BotControls();
}
void BotControls()
{
if (ChoosingXorO.botxoro == "X" && WhoseMove.whosemove == "X")
{
timerX -= Time.deltaTime;
int rand_tbX = Random.Range(0, 9);
if(tbs[rand_tbX].text != "X" && tbs[rand_tbX].text != "O")
{
if(timerX <= 0)
{
tbs[rand_tbX].text = "X";
WhoseMove.whosemove = "O";
timerX = 1f;
}
}
}
if(ChoosingXorO.botxoro == "O" && WhoseMove.whosemove == "O")
{
timerO -= Time.deltaTime;
int rand_tbO = Random.Range(0, 9);
if (tbs[rand_tbO].text != "X" && tbs[rand_tbO].text != "O")
{
if(timerO <= 0)
{
tbs[rand_tbO].text = "O";
WhoseMove.whosemove = "X";
timerO = 1f;
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
tic-tac-toe is a game with complete information, and is "solved" through
tree of game situations in accordance with the mini-max method. The total number of nodes in such a tree is 255168( wiki ). We take the alpha-beta clipping algorithm , and the level of complexity in this case will be set through the mini-max criterion, or more simply - by the depth of the viewed tree, and / or the number of viewed vertices
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question