public void SetGridSpaceStatus(GridSpaceStatus gridSpaceStatus) { this.gridSpaceStatus = gridSpaceStatus; if (gridSpaceStatus == GridSpaceStatus.WOLF) { this.GetComponent <Image>().sprite = wolfSprite; } else if (gridSpaceStatus == GridSpaceStatus.SHEEP) { this.GetComponent <Image>().sprite = sheepSprite; } else { this.GetComponent <Image>().sprite = emptySprite; } }
public GridSpace(Coordinate c, GridSpaceStatus stat) { xy = new Coordinate(c.x, c.y); status = stat; }
public List <int> GetPossibleMoves(List <GridSpace> gridSpaces, GridSpaceStatus gridSpaceStatus, int position) { possibleMoves = new List <int>(); switch (gridSpaceStatus) { case GridSpaceStatus.SHEEP: if (PieceOnBottomEdge(position) == true) { } else if (PieceOnRightEdge(position) == true) { if ( gridSpaces[position + 7].GetGridSpaceStatus() != GridSpaceStatus.WOLF && gridSpaces[position + 7].GetGridSpaceStatus() != GridSpaceStatus.SHEEP && !((position + 7) >= 64) ) { possibleMoves.Add(position + 7); } } else if (PieceOnLeftEdge(position) == true) { if ( gridSpaces[position + 9].GetGridSpaceStatus() != GridSpaceStatus.WOLF && gridSpaces[position + 9].GetGridSpaceStatus() != GridSpaceStatus.SHEEP && !((position + 9) >= 64) ) { possibleMoves.Add(position + 9); } } else { if ( gridSpaces[position + 7].GetGridSpaceStatus() != GridSpaceStatus.WOLF && gridSpaces[position + 7].GetGridSpaceStatus() != GridSpaceStatus.SHEEP && !((position + 7) >= 64) ) { possibleMoves.Add(position + 7); } if ( gridSpaces[position + 9].GetGridSpaceStatus() != GridSpaceStatus.WOLF && gridSpaces[position + 9].GetGridSpaceStatus() != GridSpaceStatus.SHEEP && !((position + 9) >= 64) ) { possibleMoves.Add(position + 9); } } break; case GridSpaceStatus.WOLF: if (PieceOnBottomEdge(position) == true) { if (position == 56) { possibleMoves.Add(49); } else { if (gridSpaces[position - 7].GetGridSpaceStatus() != GridSpaceStatus.SHEEP) { possibleMoves.Add(position - 7); } if (gridSpaces[position - 9].GetGridSpaceStatus() != GridSpaceStatus.SHEEP) { possibleMoves.Add(position - 9); } } } else if (PieceOnRightEdge(position) == true) { if (gridSpaces[position + 7].GetGridSpaceStatus() != GridSpaceStatus.SHEEP && !(position + 7 >= 64)) { possibleMoves.Add(position + 7); } if (gridSpaces[position - 9].GetGridSpaceStatus() != GridSpaceStatus.SHEEP && !(position - 9 < 0)) { possibleMoves.Add(position - 9); } } else if (PieceOnLeftEdge(position) == true) { if (gridSpaces[position - 7].GetGridSpaceStatus() != GridSpaceStatus.SHEEP && !(position - 7 < 0)) { possibleMoves.Add(position - 7); } if (gridSpaces[position + 9].GetGridSpaceStatus() != GridSpaceStatus.SHEEP && !(position + 9 >= 64)) { possibleMoves.Add(position + 9); } } else { if (gridSpaces[position + 7].GetGridSpaceStatus() != GridSpaceStatus.SHEEP && !(position + 7 >= 64)) { possibleMoves.Add(position + 7); } if (gridSpaces[position - 9].GetGridSpaceStatus() != GridSpaceStatus.SHEEP && !(position - 9 < 0)) { possibleMoves.Add(position - 9); } if (gridSpaces[position - 7].GetGridSpaceStatus() != GridSpaceStatus.SHEEP && !(position - 7 < 0)) { possibleMoves.Add(position - 7); } if (gridSpaces[position + 9].GetGridSpaceStatus() != GridSpaceStatus.SHEEP && !(position + 9 >= 64)) { possibleMoves.Add(position + 9); } } break; default: break; } return(possibleMoves); }
private Node GenerateTree(Node node, int depth, bool aiMove, Sheep sheep, Wolf wolf, GridSpaceStatus gridSpaceStatus) { switch (gridSpaceStatus) { case GridSpaceStatus.SHEEP: // Wolf loses if (wolf.GetPossibleMoves(gridSpaces, GridSpaceStatus.WOLF, wolf.position).Count == 0) { node.value = +1; sheep.bestMove = node.movePosition; sheep.bestMoveValue = +1; sheep.bestMoveDepth = depth; return(node); } if (sheep.GetPossibleMoves(gridSpaces, GridSpaceStatus.SHEEP, sheep.position).Count == 0) { node.value = -1; sheep.bestMoveValue = -1; return(node); } // Wolf wins if ( wolf.position == 1 || wolf.position == 3 || wolf.position == 5 || wolf.position == 7 ) { node.value = -1; sheep.bestMoveValue = -1; return(node); } if (aiMove == true) { foreach (int possibleMove in sheep.GetPossibleMoves(gridSpaces, GridSpaceStatus.SHEEP, sheep.position)) { Node moveNode = new Node(); sheep.position = possibleMove; node.children.Add(GenerateTree(moveNode, depth + 1, false, sheep, wolf, gridSpaceStatus)); } } else { foreach (int possibleMove in wolf.GetPossibleMoves(gridSpaces, GridSpaceStatus.WOLF, wolf.position)) { Node moveNode = new Node(); wolf.position = possibleMove; node.children.Add(GenerateTree(moveNode, depth + 1, true, sheep, wolf, gridSpaceStatus)); } } break; case GridSpaceStatus.WOLF: // Wolf wins if ( wolf.position == 1 || wolf.position == 3 || wolf.position == 5 || wolf.position == 7 ) { node.value = +1; wolf.bestMove = node.movePosition; return(node); } // Wolf loses if (wolf.GetPossibleMoves(gridSpaces, GridSpaceStatus.WOLF, wolf.position).Count == 0) { node.value = -1; return(node); } if (aiMove == true) { foreach (int possibleMove in wolf.GetPossibleMoves(gridSpaces, GridSpaceStatus.WOLF, sheep.position)) { Node moveNode = new Node(); wolf.position = possibleMove; node.children.Add(GenerateTree(moveNode, depth + 1, false, sheep, wolf, gridSpaceStatus)); } } else { foreach (int possibleMove in sheep.GetPossibleMoves(gridSpaces, GridSpaceStatus.SHEEP, wolf.position)) { // Generate possible move for each sheep? Node moveNode = new Node(); sheep.position = possibleMove; node.children.Add(GenerateTree(moveNode, depth + 1, true, sheep, wolf, gridSpaceStatus)); } } break; default: break; } return(node); }
public void SetSheep4OldPos(GridSpaceStatus Sheep4OldPos) { this.sheep4OldPos = Sheep4OldPos; }
private Node GenerateTree(Node node, int depth, bool aiMove, Sheep sheep, Wolf wolf, GridSpaceStatus gridSpaceStatus) { if ( wolf.position == 1 || wolf.position == 3 || wolf.position == 5 || wolf.position == 7 || wolf.GetPossibleMoves(gridSpaces, GridSpaceStatus.WOLF, wolf.position).Count == 0 ) { return(node); } switch (gridSpaceStatus) { case GridSpaceStatus.SHEEP: if (aiMove) { foreach (int possibleMove in sheep.GetPossibleMoves(gridSpaces, GridSpaceStatus.SHEEP, sheep.position)) { Node moveNode = new Node(); sheep.position = possibleMove; node.children.Add(GenerateTree(moveNode, depth + 1, true, sheep, wolf, gridSpaceStatus)); return(node); } } else { foreach (int possibleMove in wolf.GetPossibleMoves(gridSpaces, GridSpaceStatus.WOLF, wolf.position)) { Node moveNode = new Node(); wolf.position = possibleMove; node.children.Add(GenerateTree(moveNode, depth + 1, false, sheep, wolf, gridSpaceStatus)); return(node); } } break; case GridSpaceStatus.WOLF: if (aiMove) { foreach (int possibleMove in sheep.GetPossibleMoves(gridSpaces, GridSpaceStatus.WOLF, sheep.position)) { Node moveNode = new Node(); wolf.position = possibleMove; node.children.Add(GenerateTree(moveNode, depth + 1, true, sheep, wolf, gridSpaceStatus)); return(node); } } else { foreach (int possibleMove in wolf.GetPossibleMoves(gridSpaces, GridSpaceStatus.SHEEP, wolf.position)) { Node moveNode = new Node(); sheep.position = possibleMove; node.children.Add(GenerateTree(moveNode, depth + 1, false, sheep, wolf, gridSpaceStatus)); return(node); } } break; default: return(node); break; } }