This can be a follow-up query to coding capturing in Go. I’ve that efficiently working. I’m fairly certain that I’m not reposting, it is a utterly completely different query I’ve it simply occurs to be about the identical challenge. The sport is full apart from counting the territory on the finish. My code presently counts a few of the territory however not all of it, for simplicity’s sake I coded it to detect if a set of related empty areas is fully surrounded by stones of 1 colour it and in that case marks it as territory. Here’s a completed recreation for reference.
My query is: How do I enable the participant to click on or proper click on on a part of the board with out being contained in the replace loop? It is not contained in the replace loop as a result of replace calls a perform known as CheckVictory which calls a perform known as EndGame.
What I’m attempting to implement is to let the gamers mark the territories the place stones are useless, by left clicking so as to add a spotlight .setActive(true) and a degree, or proper clicking to cover a spotlight .setActive(false) and subtract a degree. The objective is for black to have the ability to mark their territory after which click on Go Flip to permit white to mark their territory. At present there isn’t any spotlight for a few of black’s territory within the higher proper and decrease proper of the board
Right here is my present code.
personal bool?[,] countExtraTerritory(bool?[,] currentTerritory)
{
Debug.Log("It's black's flip to assert territory not counted by the code. Click on Go Flip when you find yourself carried out. Click on to make territory, proper click on to undo clicking territory.");
bool?[,] newTerritory = new bool?[19, 19];
//Counts the territory that black claims by clicking.
whereas (passCounter < 3)
{
if (Enter.GetMouseButtonDown(0))
{
RaycastHit hit;
if (Physics.Raycast(Digicam.important.ScreenPointToRay(Enter.mousePosition), out hit, 25.0f, LayerMask.GetMask("BoardMask")))
{
mouseOver.x = ((float)Spherical(9 * (hit.level.x - goBoardOffset.x))) / 9;
mouseOver.y = ((float)Spherical(9 * (hit.level.y - goBoardOffset.y))) / 9;
if (currentTerritory[(int)(9*mouseOver.x), (int)(9*mouseOver.y)] == null)
{
newTerritory[(int)(9 * mouseOver.x), (int)(9 * mouseOver.y)] = true;
TerritoryHighlight.Occasion.HighlightTerritory(newTerritory);
}
}
else
{
mouseOver.x = -1;
mouseOver.y = -1;
}
}
if (Enter.GetMouseButtonDown(1))
{
RaycastHit hit;
if (Physics.Raycast(Digicam.important.ScreenPointToRay(Enter.mousePosition), out hit, 25.0f, LayerMask.GetMask("BoardMask")))
{
mouseOver.x = ((float)Spherical(9 * (hit.level.x - goBoardOffset.x))) / 9;
mouseOver.y = ((float)Spherical(9 * (hit.level.y - goBoardOffset.y))) / 9;
if (currentTerritory[(int)(9 * mouseOver.x), (int)(9 * mouseOver.y)] == true)
{
newTerritory[(int)(9 * mouseOver.x), (int)(9 * mouseOver.y)] = null;
TerritoryHighlight.Occasion.HighlightTerritory(newTerritory);
}
}
else
{
mouseOver.x = -1;
mouseOver.y = -1;
}
TerritoryHighlight.Occasion.hideHighlights(newTerritory);
}
}
Debug.Log("It's white's flip to assert territory not counted by the code. Click on Go Flip when you find yourself carried out. Click on to make territory, proper click on to undo clicking territory.");
whereas (passCounter < 4)
{
if (Enter.GetMouseButtonDown(0))
{
RaycastHit hit;
if (Physics.Raycast(Digicam.important.ScreenPointToRay(Enter.mousePosition), out hit, 25.0f, LayerMask.GetMask("BoardMask")))
{
mouseOver.x = ((float)Spherical(9 * (hit.level.x - goBoardOffset.x))) / 9;
mouseOver.y = ((float)Spherical(9 * (hit.level.y - goBoardOffset.y))) / 9;
if (currentTerritory[(int)(9 * mouseOver.x), (int)(9 * mouseOver.y)] == null)
{
newTerritory[(int)(9 * mouseOver.x), (int)(9 * mouseOver.y)] = false;
TerritoryHighlight.Occasion.HighlightTerritory(newTerritory);
}
}
else
{
mouseOver.x = -1;
mouseOver.y = -1;
}
}
if (Enter.GetMouseButtonDown(1))
{
RaycastHit hit;
if (Physics.Raycast(Digicam.important.ScreenPointToRay(Enter.mousePosition), out hit, 25.0f, LayerMask.GetMask("BoardMask")))
{
// Must Math.spherical() after which divide by 9 I believe. (As an alternative of (int) forged as in Checkers tutorial).
mouseOver.x = ((float)Spherical(9 * (hit.level.x - goBoardOffset.x))) / 9;
mouseOver.y = ((float)Spherical(9 * (hit.level.y - goBoardOffset.y))) / 9;
if (currentTerritory[(int)(9 * mouseOver.x), (int)(9 * mouseOver.y)] == false)
{
newTerritory[(int)(9 * mouseOver.x), (int)(9 * mouseOver.y)] = null;
TerritoryHighlight.Occasion.HighlightTerritory(newTerritory);
}
}
else
{
mouseOver.x = -1;
mouseOver.y = -1;
}
TerritoryHighlight.Occasion.hideHighlights(newTerritory);
}
}
return newTerritory;
}
Just a few notes: the mouseOver.x place is adjusted to the dimensions of the strains on the board after which is transformed again into an int, which ought to give a price from 0 to 18 anyplace on the board. I do not need assistance troubleshooting this, additionally the highlights class is distributed a bool[19,19] array, if the worth of it’s null there isn’t any spotlight, if the worth is true there’s a black spotlight, and if there’s a worth of false there’s a white spotlight.
The passCounter increments every time the button is clicked. The issue is my whereas loops are infinite loops as a result of whereas they’re executing neither the passTurn button works, nor the power to click on at a sure level and spawn a spotlight object. I’ve tried studying up on the issue and it looks as if I both must name replace once more, use a yield assertion, or an invoke assertion however they do not appear fairly like what I’m searching for.
A yield assertion delays the code for a specified time restrict, however what I wish to do is to maintain checking for a mouse click on on the board till the Go Flip button is clicked.
Often on a participant’s flip the replace perform permits them to click on on their colour stone on the suitable facet of the board and drag it into place, however now I do not need them to have the ability to do this and solely in a position to click on an area on the board and add a spotlight object or click on the Go Flip button.
I additionally tried changing the whereas statements with if statements however then the sport simply runs all of the code and finishes the sport with out permitting you to click on. At present I finish the sport by printing a message saying who received, or if the gamers tied, after which utilizing this.enabled = false;
Any assist could be drastically appreciated.