makeRandomMove method

void makeRandomMove()

Implementation

void makeRandomMove() {
  int color = _toguzFields[22];
  int numMove;
  List<int> numMoves = [];

  int startRange = 0 + (color * 9);
  int finishRange = 8 + (color * 9);

  for (var i = startRange; i <= finishRange; i++) {
    if (_toguzFields[i] > 0) {
      numMoves.add(i);
    }
  }

  if (numMoves.length == 0) {
    print("No moves (random)!");
    print(_toguzFields);
    _finished = true;
    return;
  } else if (numMoves.length == 1) {
    numMove = numMoves[0];
  } else {
    int numChoice = Random().nextInt(numMoves.length);
    numMove = numMoves[numChoice];
  }

  if (numMove > 8) {
    numMove = numMove - 9 + 1;
  } else {
    numMove = numMove + 1;
  }

  makeMove(numMove);
}