public List <OthelloZoneBehaviour> GetAdjacentZones(OthelloZoneBehaviour z) { List <OthelloZoneBehaviour> res = new List <OthelloZoneBehaviour>(); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { for (int k = -1; k <= 1; k++) { if (i == 0 && j == 0 && k == 0) { continue; } if (OthelloGameManager.Instance.ValidIndex(z.i + i) && OthelloGameManager.Instance.ValidIndex(z.j + j) && OthelloGameManager.Instance.ValidIndex(z.k + k)) { res.Add(zones[z.i + i, z.j + j, z.k + k]); } } } } return(res); }
public OthelloPieceBehaviour Put(OthelloZoneBehaviour z, bool turn) { prefab = GameObject.Find("OthelloPiecePrefab"); color = turn; OthelloPieceBehaviour p = base.Spawn(z.transform.position, Quaternion.identity).GetComponent <OthelloPieceBehaviour>(); p.color = turn; p.gameObject.transform.parent = z.transform; p.gameObject.GetComponent <Renderer>().material.color = color ? Color.white : new Color(0.5f, 0, 0.5f, 1); z.AddPiece(p); return(p); }
//put piece ignoring rules other than the "no putting pieces in occupied zones" rule public bool ForcePut(OthelloZoneBehaviour z, bool turn) { if (!z.IsEmpty()) { return(false); } OthelloPieceBehaviour newPiece = new GameObject().AddComponent <OthelloPieceBehaviour>(); newPiece = newPiece.Put(z, turn); newPiece.gameObject.GetComponent <MeshRenderer>().enabled = true; foreach (OthelloZoneBehaviour a in boardReference.GetAdjacentZones(z)) { if (a.IsEmpty()) { possibleZones.Add(a); } } possibleZones.Remove(z); return(true); }
public bool PutPieceCheck(OthelloZoneBehaviour z, bool turn) { if (!z.IsEmpty()) { return(false); } for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { for (int k = -1; k <= 1; k++) { if (i == 0 && j == 0 && k == 0) { continue; } int zi = z.i, zj = z.j, zk = z.k; int dist = 0; OthelloPieceBehaviour currPiece; while ( ValidIndex(zi + i) && ValidIndex(zj + j) && ValidIndex(zk + k) ) { zi += i; zj += j; zk += k; dist++; currPiece = boardReference.GetZone(zi, zj, zk).GetPiece(); if (!currPiece) { break; } if (currPiece.GetColor == turn && dist > 1) { return(true); } } } } } return(false); }
public void PutPiece(OthelloZoneBehaviour z, bool turn) { OthelloPieceBehaviour newPiece = new GameObject().AddComponent <OthelloPieceBehaviour>(); newPiece = newPiece.Put(z, turn); newPiece.gameObject.GetComponent <MeshRenderer>().enabled = true; if (turn) { whiteNum += 1; } else { blackNum += 1; } for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { for (int k = -1; k <= 1; k++) { if (i == 0 && j == 0 && k == 0) { continue; } int zi = z.i, zj = z.j, zk = z.k; OthelloPieceBehaviour currPiece; List <OthelloPieceBehaviour> toFlip = new List <OthelloPieceBehaviour>(); while ( ValidIndex(zi + i) && ValidIndex(zj + j) && ValidIndex(zk + k) ) { zi += i; zj += j; zk += k; currPiece = boardReference.GetZone(zi, zj, zk).GetPiece(); if (!currPiece) { break; } if (currPiece.GetColor == /*z.GetPiece().GetColor*/ turn) { foreach (OthelloPieceBehaviour p in toFlip) { p.Flip(); } break; } toFlip.Add(currPiece); } } } } foreach (OthelloZoneBehaviour a in boardReference.GetAdjacentZones(z)) { if (a.IsEmpty()) { possibleZones.Add(a); } } possibleZones.Remove(z); ChangeTurn(); }