private void CheckCaptureDLDiagonal(int x, int y) { try { Stone[,] stones = gameScreen.Stones; StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White; if (x - 1 < 0 || y + 1 > stones.GetLength(0) - 1) { return; } if (stones[y + 1, x - 1].CurrentState == currentState || stones[y + 1, x - 1].CurrentState == StoneState.Open) { return; } if (x - 2 < 0 || y + 2 > stones.GetLength(0) - 1) { return; } if (stones[y + 2, x - 2].CurrentState == currentState || stones[y + 2, x - 2].CurrentState == StoneState.Open) { return; } if (x - 3 < 0 || y + 3 > stones.GetLength(0) - 1) { return; } if (stones[y + 3, x - 3].CurrentState != currentState) { return; } CurrentPlayer.Captures++; stones[y + 1, x - 1].CurrentState = StoneState.Open; stones[y + 2, x - 2].CurrentState = StoneState.Open; } catch { } }
private void CheckCaptureURDiagonal(int x, int y) { try { Stone[,] stones = gameScreen.Stones; StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White; if (x + 1 > stones.GetLength(1) - 1 || y - 1 < 0) { return; } if (stones[y - 1, x + 1].CurrentState == currentState || stones[y - 1, x + 1].CurrentState == StoneState.Open) { return; } if (x + 2 > stones.GetLength(1) - 1 || y - 1 < 0) { return; } if (stones[y - 2, x + 2].CurrentState == currentState || stones[y - 2, x + 2].CurrentState == StoneState.Open) { return; } if (x + 3 > stones.GetLength(1) - 1 || y - 1 < 0) { return; } if (stones[y - 3, x + 3].CurrentState != currentState) { return; } CurrentPlayer.Captures++; stones[y - 1, x + 1].CurrentState = StoneState.Open; stones[y - 2, x + 2].CurrentState = StoneState.Open; } catch { } }
private bool CheckDiagonalTria(int x, int y) { StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White; Stone[,] stones = gameScreen.Stones; bool tria = false; if (x - 1 >= 0 && y - 1 >= 0 && stones[y - 1, x - 1].CurrentState == StoneState.Open) { if (x + 1 <= stones.GetLength(1) - 1 && y - 1 <= stones.GetLength(0) - 1 && stones[y + 1, x + 1].CurrentState == StoneState.Open) { tria = CheckDiagDLtoURTria(currentState, stones, x, y); } else if (x + 1 <= stones.GetLength(1) - 1 && y + 1 <= stones.GetLength(0) - 1 && stones[y + 1, x + 1].CurrentState == currentState) { if (x + 2 <= stones.GetLength(1) - 1 && y + 2 <= stones.GetLength(0) - 1 && stones[y + 2, x + 2].CurrentState == currentState) { if (x + 3 <= stones.GetLength(1) - 1 && y + 3 <= stones.GetLength(0) - 1 && stones[y + 3, x + 3].CurrentState == StoneState.Open) { tria = true; } } } } else if (x + 1 <= stones.GetLength(1) - 1 && y + 1 <= stones.GetLength(0) - 1 && stones[y + 1, x + 1].CurrentState == StoneState.Open) { if (x - 1 >= 0 && y - 1 >= 0 && stones[y - 1, x - 1].CurrentState == currentState) { if (x - 2 >= 0 && y - 2 >= 0 && stones[y - 2, x - 2].CurrentState == currentState) { if (x - 3 >= 0 && y - 3 >= 0 && stones[y - 3, x - 3].CurrentState == StoneState.Open) { tria = true; } } } } else if (x + 1 <= stones.GetLength(1) - 1 && y + 1 <= stones.GetLength(0) - 1 && stones[y + 1, x + 1].CurrentState == currentState) { if (x - 1 >= 0 && y - 1 >= 0 && stones[y - 1, x - 1].CurrentState == currentState) { if (x - 2 >= 0 && y - 2 >= 0 && stones[y - 2, x - 2].CurrentState == StoneState.Open) { if (x + 2 <= stones.GetLength(1) - 1 && y + 2 <= stones.GetLength(0) - 1 && stones[y + 2, x + 2].CurrentState == StoneState.Open) { tria = true; } } } } return(tria); }
private bool CheckDiagDLtoURTria(StoneState currentState, Stone[,] stones, int x, int y) { bool tria = false; int maxYBound = stones.GetLength(0) - 1; int maxXBound = stones.GetLength(1) - 1; if (x + 1 <= maxXBound && y - 1 >= 0 && stones[y - 1, x + 1].CurrentState == StoneState.Open) { if (x - 1 >= 0 && y + 1 <= maxYBound && stones[y + 1, x - 1].CurrentState == currentState) { if (x - 2 >= 0 && y + 2 <= maxYBound && stones[y + 2, x - 2].CurrentState == currentState) { if (x - 3 >= 0 && y + 3 <= maxYBound && stones[y + 3, x - 3].CurrentState == StoneState.Open) { tria = true; } } } } else if (x - 1 >= 0 && y + 1 <= maxYBound && stones[y + 1, x - 1].CurrentState == StoneState.Open) { if (x + 1 <= maxXBound && y - 1 >= 0 && stones[y - 1, x + 1].CurrentState == currentState) { if (x + 2 <= maxXBound && y - 2 >= 0 && stones[y - 2, x + 2].CurrentState == currentState) { if (x + 3 <= maxXBound && y - 3 >= 0 && stones[y - 3, x + 3].CurrentState == StoneState.Open) { tria = true; } } } } else if (x + 1 <= maxXBound && y - 1 >= 0 && stones[y - 1, x + 1].CurrentState == currentState) { if (x - 1 >= 0 && y + 1 <= maxYBound && stones[y + 1, x - 1].CurrentState == currentState) { if (x - 2 >= 0 && y + 2 <= maxYBound && stones[y + 2, x - 2].CurrentState == StoneState.Open) { if (x + 2 <= maxXBound && y - 2 >= 0 && stones[y - 2, x + 2].CurrentState == StoneState.Open) { tria = true; } } } } return(tria); }
// private method private void changeColor(StoneState state, int x, int z) { switch (state) { case StoneState.Black: createStones[x, z].transform.Rotate(180, 0, 0); break; case StoneState.White: createStones[x, z].transform.Rotate(0, 0, 0); createStones[x, z].SetActive(true); break; default: break; } }
private int CheckRowDiagonalRL(int x, int y) { int count = 0; StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White; Stone[,] stones = gameScreen.Stones; for (int i = 0; i < 5; i++) { if (x - i < 0 || y - i < 0) { break; } else { if (stones[y - i, x - i].CurrentState == currentState) { count++; } else { break; } } } for (int i = 1; i < 5; i++) { if (x + i > stones.GetLength(1) - 1 || y + i > stones.GetLength(0) - 1) { break; } else { if (stones[y + i, x + i].CurrentState == currentState) { count++; } else { break; } } } return(count); }
private bool CheckVerticalTessera(int x, int y) { StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White; Stone[,] stones = gameScreen.Stones; bool tessera = false; int maxYValue = stones.GetLength(0) - 1; int maxXValue = stones.GetLength(1) - 1; bool startedT = false; int count = 0; for (var i = 0; i < maxYValue; i++) { if (stones[i, x].CurrentState == currentState) { if (!startedT && i - 1 >= 0 && stones[i - 1, x].CurrentState == StoneState.Open) { startedT = true; } if (startedT) { count++; } } else if (stones[i, x].CurrentState == StoneState.Open) { if (count == 4 && i - 1 >= 0 && stones[i - 1, x].CurrentState == currentState) { tessera = true; } else { startedT = false; count = 0; } } else { startedT = false; count = 0; } } return(tessera); }
private bool CheckDLtoURTessera(int x, int y) { StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White; Stone[,] stones = gameScreen.Stones; bool tessera = true; int maxYValue = stones.GetLength(0) - 1; int maxXValue = stones.GetLength(1) - 1; int disFromCurPoint = 0; while (CheckBounds(x - disFromCurPoint, y + disFromCurPoint) && stones[y + disFromCurPoint, x - disFromCurPoint].CurrentState == currentState) { disFromCurPoint++; } disFromCurPoint--; int startX = x - disFromCurPoint; int startY = y + disFromCurPoint; for (int i = 0; i < 4; i++) { if (CheckBounds(startX + i, startY - i) && stones[startY - i, startX + i].CurrentState != currentState) { tessera = false; break; } } if (!CheckBounds(startX - 1, startY + 1) || (CheckBounds(startX - 1, startY + 1) && stones[startY + 1, startX - 1].CurrentState != StoneState.Open)) { if (!CheckBounds(startX + 4, startY - 4) || (CheckBounds(startX + 4, startY - 4) && stones[startY - 4, startX + 4].CurrentState != StoneState.Open)) { tessera = false; } } return(tessera); }
private void CheckCaptureULDiagonal(int x, int y) { try { Stone[,] stones = gameScreen.Stones; if (x < 3 || y < 3) { return; } StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White; if (x - 1 < 0 || y - 1 < 0) { return; } if (stones[y - 1, x - 1].CurrentState == currentState || stones[y - 1, x - 1].CurrentState == StoneState.Open) { return; } if (x - 2 < 0 || y - 2 < 0) { return; } if (stones[y - 2, x - 2].CurrentState == currentState || stones[y - 2, x - 2].CurrentState == StoneState.Open) { return; } if (x - 3 < 0 || y - 3 < 0) { return; } if (stones[y - 3, x - 3].CurrentState != currentState || stones[y - 3, x - 3].CurrentState == StoneState.Open) { return; } CurrentPlayer.Captures++; stones[y - 1, x - 1].CurrentState = StoneState.Open; stones[y - 2, x - 2].CurrentState = StoneState.Open; } catch { } }
private void CheckCaptureDown(int x, int y) { try { Stone[,] stones = gameScreen.Stones; if (y > stones.GetLength(0) - 4) { return; } StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White; if (y + 1 > stones.GetLength(0) - 1) { return; } if (stones[y + 1, x].CurrentState == currentState || stones[y + 1, x].CurrentState == StoneState.Open) { return; } if (y + 2 > stones.GetLength(0) - 1) { return; } if (stones[y + 2, x].CurrentState == currentState || stones[y + 2, x].CurrentState == StoneState.Open) { return; } if (y + 3 > stones.GetLength(0) - 1) { return; } if (stones[y + 3, x].CurrentState != currentState) { return; } CurrentPlayer.Captures++; stones[y + 1, x].CurrentState = StoneState.Open; stones[y + 2, x].CurrentState = StoneState.Open; } catch { } }
private void CheckCaptureRight(int x, int y) { try { Stone[,] stones = gameScreen.Stones; if (x > stones.GetLength(1) - 4) { return; } StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White; if (x + 1 > stones.GetLength(1) - 1) { return; } if (stones[y, x + 1].CurrentState == currentState || stones[y, x + 1].CurrentState == StoneState.Open) { return; } if (x + 2 > stones.GetLength(1) - 1) { return; } if (stones[y, x + 2].CurrentState == currentState || stones[y, x + 2].CurrentState == StoneState.Open) { return; } if (x + 3 > stones.GetLength(1) - 1) { return; } if (stones[y, x + 3].CurrentState != currentState) { return; } CurrentPlayer.Captures++; stones[y, x + 1].CurrentState = StoneState.Open; stones[y, x + 2].CurrentState = StoneState.Open; } catch { } }
private bool CheckVerticalTria(int x, int y) { Stone[,] stones = gameScreen.Stones; StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White; bool tria = false; if (y == 0 || x == stones.GetLength(0) - 1) { tria = false; } if (y - 1 >= 0 && stones[y - 1, x].CurrentState == currentState) { if (y - 2 >= 0 && stones[y - 2, x].CurrentState == StoneState.Open) { if (y + 1 <= stones.GetLength(0) - 1 && stones[y + 1, x].CurrentState == currentState) { if (y + 2 <= stones.GetLength(0) - 1 && stones[y + 2, x].CurrentState == StoneState.Open) { tria = true; } } } else if (y - 2 >= 0 && stones[y - 2, x].CurrentState == currentState) { if (y - 3 >= 0 && stones[y - 3, x].CurrentState == StoneState.Open) { if (y + 1 <= stones.GetLength(1) - 1 && stones[y + 1, x].CurrentState == StoneState.Open) { tria = true; } } } } else if (y - 1 >= 0 && stones[y - 1, x].CurrentState == StoneState.Open) { if (y + 1 <= stones.GetLength(0) - 1 && stones[y + 1, x].CurrentState == currentState) { if (y + 2 <= stones.GetLength(0) - 1 && stones[y + 2, x].CurrentState == currentState) { if (y + 3 <= stones.GetLength(0) - 1 && stones[y + 3, x].CurrentState == StoneState.Open) { tria = true; } } } } else if (y + 1 <= stones.GetLength(0) - 1 && stones[y + 1, x].CurrentState == StoneState.Open) { if (y - 1 >= 0 && stones[y - 1, x].CurrentState == currentState) { if (y - 2 >= 0 && stones[y - 2, x].CurrentState == currentState) { if (y - 3 >= 0 && stones[y - 3, x].CurrentState == currentState) { if (y - 4 >= 0 && stones[y - 4, x].CurrentState == StoneState.Open) { tria = true; } } } } } return(tria); }
private bool CheckHorizontalTria(int x, int y) { StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White; Stone[,] stones = gameScreen.Stones; bool tria = false; if (x == 0 || x == stones.GetLength(1) - 1) { tria = false; } if (x - 1 >= 0 && stones[y, x - 1].CurrentState == currentState) { if (x - 2 >= 0 && stones[y, x - 2].CurrentState == StoneState.Open) { if (x + 1 <= stones.GetLength(1) - 1 && stones[y, x + 1].CurrentState == currentState) { if (x + 2 <= stones.GetLength(1) - 1 && stones[y, x + 2].CurrentState == StoneState.Open) { tria = true; } } } else if (x - 2 >= 0 && stones[y, x - 2].CurrentState == currentState) { if (x - 3 >= 0 && stones[y, x - 3].CurrentState == StoneState.Open) { if (x + 1 <= stones.GetLength(1) - 1 && stones[y, x + 1].CurrentState == StoneState.Open) { tria = true; } } } } else if (x - 1 >= 0 && stones[y, x - 1].CurrentState == StoneState.Open) { if (x + 1 <= stones.GetLength(1) - 1 && stones[y, x + 1].CurrentState == currentState) { if (x + 2 <= stones.GetLength(1) - 1 && stones[y, x + 2].CurrentState == currentState) { if (x + 3 <= stones.GetLength(1) - 1 && stones[y, x + 3].CurrentState == StoneState.Open) { tria = true; } } } } else if (x + 1 <= stones.GetLength(1) - 1 && stones[y, x + 1].CurrentState == StoneState.Open) { if (x - 1 >= 0 && stones[y, x - 1].CurrentState == currentState) { if (x - 2 >= 0 && stones[y, x - 2].CurrentState == currentState) { if (x - 3 >= 0 && stones[y, x - 3].CurrentState == currentState) { if (x - 4 >= 0 && stones[y, x - 4].CurrentState == StoneState.Open) { tria = true; } } } } } return(tria); }
public static Brush GetBrush(this StoneState state) { return(StoneStateToColor[state]); }
public Stone() { CurrentState = StoneState.Open; Foreground = new SolidColorBrush(Colors.Transparent); }