public GameObject createGameTile(int id) //Created the game tile object { ResistileServer.GameTile gameTile = getGameTile(id); //Tile data var tile = Instantiate(tilePrefab); //Tile Object TileData tileData = tile.GetComponent <TileData>(); if (gameTile.type.Contains("Resistor")) { tile.GetComponentInChildren <Text>().text = gameTile.resistance.ToString(); //Set Resistance text on tile tileData.resistance = gameTile.resistance; //Set Resistance data on TileData if (gameTile.type.Equals(ResistileServer.GameTileTypes.Resistor.typeI)) { tile.transform.FindChild("Background").GetComponent <Image>().sprite = resI; tileData.type = ResistileServer.GameTileTypes.Resistor.typeI; } else if (gameTile.type.Equals(ResistileServer.GameTileTypes.Resistor.typeII)) { tile.transform.FindChild("Background").GetComponent <Image>().sprite = resII; tileData.type = ResistileServer.GameTileTypes.Resistor.typeII; } } else { tile.transform.FindChild("OhmIcon").gameObject.SetActive(false); //Disable Ohm Icon tile.transform.FindChild("Resistance").gameObject.SetActive(false); //Disable resistance text if (gameTile.type.Contains("Wire")) { if (gameTile.type.Equals(ResistileServer.GameTileTypes.Wire.typeI)) //Wire Straight { tile.transform.FindChild("Background").GetComponent <Image>().sprite = wireI; tileData.type = ResistileServer.GameTileTypes.Wire.typeI; } else if (gameTile.type.Equals(ResistileServer.GameTileTypes.Wire.typeII)) //Wire Bend { tile.transform.FindChild("Background").GetComponent <Image>().sprite = wireII; tileData.type = ResistileServer.GameTileTypes.Wire.typeII; } else if (gameTile.type.Equals(ResistileServer.GameTileTypes.Wire.typeT)) //Wire T { tile.transform.FindChild("Background").GetComponent <Image>().sprite = wireIII; tileData.type = ResistileServer.GameTileTypes.Wire.typeT; } } else if (gameTile.type == ResistileServer.GameTileTypes.solder) { tile.transform.FindChild("Background").GetComponent <Image>().sprite = solder; tileData.type = ResistileServer.GameTileTypes.solder; } } tileData.tileID = gameTile.id; return(tile); }
public void Draw(int tileID) { ResistileServer.GameTile gameTile = getGameTile(tileID); GameObject tile = createGameTile(tileID); if (gameTile.type.Contains("Resistor") || gameTile.type == ResistileServer.GameTileTypes.solder) { tile.transform.SetParent(resHand.transform, false); } else if (gameTile.type.Contains("Wire")) { tile.transform.SetParent(wireHand.transform, false); } }
private void GetValue(GameTile tile, int[] coordinates) { int x; int y; string oppositeDirection; x = coordinates[0] + 1; y = coordinates[1]; oppositeDirection = Directions.left; if (tile.neighbors[Directions.right] == null && !IsOutOfBoard(x, y) && board[x, y] != null) { board[x, y].neighbors[oppositeDirection] = tile; tile.neighbors[Directions.right] = board[x, y]; } }
public void testCalculateThreePaths() { var boardManager = new BoardManager(); for (var i = 1; i < 6; i++) { boardManager.AddTile(new GameTile(GameTileTypes.Wire.typeI), new[] { i, 0 }); } boardManager.AddTile(new GameTile(GameTileTypes.Wire.typeT), new[] { 6, 0 }); boardManager.AddTile(new GameTile(GameTileTypes.Wire.typeT), new[] { 7, 0 }); boardManager.AddTile(new GameTile(GameTileTypes.Resistor.typeII, 0, 4), new[] { 8, 0 }); var tile = new GameTile(GameTileTypes.Wire.typeI); tile.Rotate(); boardManager.AddTile(tile, new[] { 6, 1 }); tile = new GameTile(GameTileTypes.Resistor.typeII, 0, 12); tile.Rotate(); tile.Rotate(); boardManager.AddTile(tile, new[] { 6, 2 }); tile = new GameTile(GameTileTypes.Wire.typeI); boardManager.AddTile(tile, new[] { 7, 2 }); tile = new GameTile(GameTileTypes.Resistor.typeII, 0, 12); tile.Rotate(); tile.Rotate(); boardManager.AddTile(tile, new[] { 7, 1 }); tile = new GameTile(GameTileTypes.Wire.typeT); tile.Rotate(); boardManager.AddTile(tile, new[] { 8, 1 }); tile = new GameTile(GameTileTypes.Wire.typeT); tile.Rotate(); boardManager.AddTile(tile, new[] { 8, 2 }); for (var i = 3; i < 8; i++) { tile = new GameTile(GameTileTypes.Wire.typeI); tile.Rotate(); boardManager.AddTile(tile, new[] { 8, i }); } var result = boardManager.Calculate(); Assert.IsTrue(result.IsLessThan(4.1) && result.IsGreaterThan(3.9)); }
public void GameEndingLioop() { var boardManager = new BoardManager(); var tile = new GameTile(GameTileTypes.Wire.typeI, -1); var res = new GameTile(GameTileTypes.Resistor.typeII, 0, 4); var tile2 = new GameTile(GameTileTypes.Wire.typeII, -1); tile2.Rotate(); var res2 = new GameTile(GameTileTypes.Resistor.typeI, 0, 3); var tile3 = new GameTile(GameTileTypes.Wire.typeII, -1); tile3.Rotate(); tile3.Rotate(); var check = boardManager.IsValidMove(tile, new int[] { 1, 0 }); Assert.IsTrue(check, "Is tile placed"); if (check == true) { boardManager.AddTile(tile, new int[] { 1, 0 }); } check = boardManager.IsValidMove(res, new int[] { 2, 0 }); Assert.IsTrue(check, "Is resistor placed"); if (check) { boardManager.AddTile(res, new int[] { 2, 0 }); } check = boardManager.IsValidMove(tile2, new int[] { 2, 1 }); Assert.IsTrue(check, "Is resistor placed"); if (check == true) { boardManager.AddTile(tile2, new int[] { 2, 1 }); } check = boardManager.IsValidMove(res2, new int[] { 1, 1 }); Assert.IsTrue(check, "Is resistor placed"); if (check == true) { boardManager.AddTile(res2, new int[] { 1, 1 }); } check = boardManager.IsValidMove(tile3, new int[] { 0, 1 }); Assert.IsTrue(check, "Is resistor placed"); if (check == true) { boardManager.AddTile(tile3, new int[] { 0, 1 }); } }
public void testCalculateOnePath() { var boardManager = new BoardManager(); for (var i = 1; i < 8; i++) { boardManager.AddTile(new GameTile(GameTileTypes.Wire.typeI), new [] { i, 0 }); } boardManager.AddTile(new GameTile(GameTileTypes.Wire.typeII), new[] { 8, 0 }); for (var i = 1; i < 8; i++) { var tile = new GameTile(GameTileTypes.Wire.typeI); tile.Rotate(); boardManager.AddTile(tile, new [] { 8, i }); } var result = boardManager.Calculate(); Assert.IsTrue(result.IsLessThan(0.1) && result.IsGreaterThan(-0.1)); }
public void ProperResistorWire() { var boardManager = new BoardManager(); var tile = new GameTile(GameTileTypes.Wire.typeI, -1); var res = new GameTile(GameTileTypes.Resistor.typeI, 0, 4); var check = boardManager.IsValidMove(tile, new int[] { 1, 0 }); Assert.IsTrue(check); if (check == true) { boardManager.AddTile(tile, new int[] { 1, 0 }); } check = boardManager.IsValidMove(res, new int[] { 2, 0 }); Assert.IsTrue(check); if (check == true) { boardManager.AddTile(res, new int[] { 2, 0 }); } }
public void ProperTwoTiles() { var boardManager = new BoardManager(); var tile = new GameTile(GameTileTypes.Wire.typeI, -1); var check = boardManager.IsValidMove(tile, new int[] { 1, 0 }); Assert.IsTrue(check); if (check == true) { boardManager.AddTile(tile, new int[] { 1, 0 }); } Assert.IsNotNull(boardManager.board[1, 0], "Is tile placed"); tile = new GameTile(GameTileTypes.Wire.typeII, -1); check = boardManager.IsValidMove(tile, new int[] { 2, 0 }); if (check == true) { boardManager.AddTile(tile, new int[] { 2, 0 }); } Assert.IsNotNull(boardManager.board[2, 0], "Is tile placed"); Assert.IsTrue(check, "Case 3: Straight followed by Angle"); }
public void placeTile(int tileID, int x, int y, int rotate) { ResistileServer.GameTile gameTile = getGameTile(tileID); GameObject boardNode = BoardHandler.GetNodeAt(x, y); if (gameTile.type.Contains("Wire")) { foreach (Transform wireTile in wireHand.transform) { if (wireTile.gameObject.GetComponent <TileData>().tileID == tileID) { while (wireTile.GetComponent <TileData>().rotation != 0) { wireTile.GetComponent <RotateTile>().TaskOnClick(); } wireTile.transform.SetParent(boardNode.transform, false); wireTile.transform.SetAsFirstSibling(); removeRotate(wireTile.gameObject); for (int i = 0; i < rotate; i++) { wireTile.GetComponent <RotateTile>().TaskOnClick(); } } } } else { var tile = createGameTile(tileID); tile.transform.SetParent(boardNode.transform, false); tile.GetComponent <Draggable>().enabled = false; removeRotate(tile); tile.transform.SetAsFirstSibling(); for (int i = 0; i < rotate; i++) { tile.GetComponent <RotateTile>().TaskOnClick(); } } }
public void AddTile(GameTile tile, int[] coordinates) { board[coordinates[0], coordinates[1]] = tile; // Assume valid move, find non blocked directions of tile, // if neighbors exist: // connect all neigbors to corresponding direction //up int x = coordinates[0]; int y = coordinates[1] - 1; string oppositeDirection = Directions.down; if (tile.neighbors[Directions.up] == null && !IsOutOfBoard(x, y) && board[x, y] != null) { board[x, y].neighbors[oppositeDirection] = tile; tile.neighbors[Directions.up] = board[x, y]; } //left x = coordinates[0] - 1; y = coordinates[1]; oppositeDirection = Directions.right; if (tile.neighbors[Directions.left] == null && !IsOutOfBoard(x, y) && board[x, y] != null) { board[x, y].neighbors[oppositeDirection] = tile; tile.neighbors[Directions.left] = board[x, y]; } //down x = coordinates[0]; y = coordinates[1] + 1; oppositeDirection = Directions.up; if (tile.neighbors[Directions.down] == null && !IsOutOfBoard(x, y) && board[x, y] != null) { board[x, y].neighbors[oppositeDirection] = tile; tile.neighbors[Directions.down] = board[x, y]; } //right GetValue(tile, coordinates); }
private void addOneWireToAdjacentTWires() { foreach (GameTile gameTile in board) { if (gameTile != null && gameTile.type == GameTileTypes.Wire.typeT) { var neighbors = gameTile.neighbors.ToList(); for (int index = 0; index < neighbors.Count; index++) { var neighbor = neighbors[index]; if (neighbor.Value.type == GameTileTypes.Wire.typeT) { var facingDirection = Directions.Facing[neighbor.Key]; var tileToBeAdded = new GameTile(GameTileTypes.Wire.typeI, 1); gameTile.neighbors[neighbor.Key] = tileToBeAdded; tileToBeAdded.neighbors[Directions.left] = gameTile; tileToBeAdded.neighbors[Directions.right] = neighbor.Value; neighbor.Value.neighbors[facingDirection] = tileToBeAdded; } } } } }
public DeckManager() { int i; /* * WIRES */ for (i = 0; i < cardCounts[GameTileTypes.Wire.typeI]; i++) //Straight Wires { var tile = new GameTile(GameTileTypes.Wire.typeI, CreateId()); wireDeck.Push(tile); allTiles.Add(tile.id, tile); } for (i = 0; i < cardCounts[GameTileTypes.Wire.typeII]; i++) //Angle Wires { var tile = new GameTile(GameTileTypes.Wire.typeII, CreateId()); wireDeck.Push(tile); allTiles.Add(tile.id, tile); } for (i = 0; i < cardCounts[GameTileTypes.Wire.typeT]; i++) //T Wires { var tile = new GameTile(GameTileTypes.Wire.typeT, CreateId()); wireDeck.Push(tile); allTiles.Add(tile.id, tile); } /* * STRAIGHT RESISTORS */ for (i = 0; i < cardCounts[GameTileTypes.Resistor.typeI]; i++) { if (i < 6) { var tile = new GameTile(GameTileTypes.Resistor.typeI, CreateId(), 1); resistorSolderDeck.Push(tile); allTiles.Add(tile.id, tile); } else if (i < 12) { var tile = new GameTile(GameTileTypes.Resistor.typeI, CreateId(), 2); resistorSolderDeck.Push(tile); allTiles.Add(tile.id, tile); } else if (i < 17) { var tile = new GameTile(GameTileTypes.Resistor.typeI, CreateId(), 3); resistorSolderDeck.Push(tile); allTiles.Add(tile.id, tile); } else if (i < 21) { var tile = new GameTile(GameTileTypes.Resistor.typeI, CreateId(), 4); resistorSolderDeck.Push(tile); allTiles.Add(tile.id, tile); } else { var tile = new GameTile(GameTileTypes.Resistor.typeI, CreateId(), 5); resistorSolderDeck.Push(tile); allTiles.Add(tile.id, tile); } } /* * ANGLE RESISTORS */ for (i = 0; i < cardCounts[GameTileTypes.Resistor.typeII]; i++) { if (i < 6) { var tile = new GameTile(GameTileTypes.Resistor.typeII, CreateId(), 1); resistorSolderDeck.Push(tile); allTiles.Add(tile.id, tile); } else if (i < 12) { var tile = new GameTile(GameTileTypes.Resistor.typeII, CreateId(), 2); resistorSolderDeck.Push(tile); allTiles.Add(tile.id, tile); } else if (i < 17) { var tile = new GameTile(GameTileTypes.Resistor.typeII, CreateId(), 3); resistorSolderDeck.Push(tile); allTiles.Add(tile.id, tile); } else if (i < 21) { var tile = new GameTile(GameTileTypes.Resistor.typeII, CreateId(), 4); resistorSolderDeck.Push(tile); allTiles.Add(tile.id, tile); } else { var tile = new GameTile(GameTileTypes.Resistor.typeII, CreateId(), 5); resistorSolderDeck.Push(tile); allTiles.Add(tile.id, tile); } } /* * SOLDER */ for (i = 0; i < cardCounts[GameTileTypes.solder]; i++) { var tile = new GameTile(GameTileTypes.solder, CreateId()); resistorSolderDeck.Push(tile); allTiles.Add(tile.id, tile); } /* * SHUFFLE */ Shuffle(wireDeck); Shuffle(wireDeck); Shuffle(resistorSolderDeck); Shuffle(resistorSolderDeck); }
public bool IsValidSolder(GameTile newtile, Coordinates coordinates) { if (board[coordinates.x(), coordinates.y()] == null) { return(false); } var tileOnBoard = board[coordinates.x(), coordinates.y()]; //up if (newtile.neighbors[Directions.up] == null) { var newcoords = coordinates.up(); var test = IsOutOfBoard(newcoords.x(), newcoords.y()); if (test) { return(false); } var testedNeighbor = board[newcoords.x(), newcoords.y()]; if (testedNeighbor != null && testedNeighbor.neighbors[Directions.down] == GameTile.blockedDirectionTile) { return(false); } } else { var newcoords = coordinates.up(); var test = IsOutOfBoard(newcoords.x(), newcoords.y()); if (!test) { var testedNeighbor = board[newcoords.x(), newcoords.y()]; if (testedNeighbor != null && testedNeighbor.neighbors[Directions.down] == GameTile.blockedDirectionTile) { return(false); } } } //down if (newtile.neighbors[Directions.down] == null) { var newcoords = coordinates.down(); var test = IsOutOfBoard(newcoords.x(), newcoords.y()); if (test) { return(false); } var testedNeighbor = board[newcoords.x(), newcoords.y()]; if (testedNeighbor != null && testedNeighbor.neighbors[Directions.up] == GameTile.blockedDirectionTile) { return(false); } } else { var newcoords = coordinates.down(); var test = IsOutOfBoard(newcoords.x(), newcoords.y()); if (!test) { var testedNeighbor = board[newcoords.x(), newcoords.y()]; if (testedNeighbor != null && testedNeighbor.neighbors[Directions.up] == GameTile.blockedDirectionTile) { return(false); } } } //left if (newtile.neighbors[Directions.left] == null) { var newcoords = coordinates.left(); var test = IsOutOfBoard(newcoords.x(), newcoords.y()); if (test) { return(false); } var testedNeighbor = board[newcoords.x(), newcoords.y()]; if (testedNeighbor != null && testedNeighbor.neighbors[Directions.right] == GameTile.blockedDirectionTile) { return(false); } } else { var newcoords = coordinates.left(); var test = IsOutOfBoard(newcoords.x(), newcoords.y()); if (!test) { var testedNeighbor = board[newcoords.x(), newcoords.y()]; if (testedNeighbor != null && testedNeighbor.neighbors[Directions.right] == GameTile.blockedDirectionTile) { return(false); } } } //right if (newtile.neighbors[Directions.right] == null) { var newcoords = coordinates.right(); var test = IsOutOfBoard(newcoords.x(), newcoords.y()); if (test) { return(false); } var testedNeighbor = board[newcoords.x(), newcoords.y()]; if (testedNeighbor != null && testedNeighbor.neighbors[Directions.left] == GameTile.blockedDirectionTile) { return(false); } } else { var newcoords = coordinates.right(); var test = IsOutOfBoard(newcoords.x(), newcoords.y()); if (!test) { var testedNeighbor = board[newcoords.x(), newcoords.y()]; if (testedNeighbor != null && testedNeighbor.neighbors[Directions.left] == GameTile.blockedDirectionTile) { return(false); } } } return(true); }
public bool IsValidSolder(GameTile newtile, int[] coordinates) { return(IsValidSolder(newtile, new Coordinates(coordinates[0], coordinates[1]))); }
public void solderTile(GameTile newTile, int[] coordinates) { //Delete current tile AddTile(newTile, coordinates); }
public double Calculate() { // every open end should reference to blocked direction tile blockOpenEnds(); Console.WriteLine("blocked open ends"); //addOneWireToAdjacentTWires(); Console.WriteLine("added wires to any adjacent Ts"); var paths = FindAllPaths(); Console.WriteLine("Found all paths"); // one path, return sum of all. if (paths.Count == 0) { Console.WriteLine("No Paths Found... Something went wrong."); return(-2); } if (paths.Count == 1) { return(paths[0].Sum(gameTile => gameTile.resistance)); } else { //first, put current index in each tile in paths. int currentIndex = 0; var allTWires = new List <GameTile>(); foreach (var path in paths) { GameTile previousTile = path[0]; //should be endTile at the beginning. for (var i = 1; i < path.Count; i++) { GameTile tile = path[i]; if (tile.firstAccessor == null) { tile.firstAccessor = previousTile; tile.currentIndex = currentIndex; } if (tile.type == GameTileTypes.Wire.typeT) { currentIndex++; if (!allTWires.Contains(tile) && tile != startTile) { allTWires.Add(tile); } } previousTile = tile; } } Console.WriteLine("All indexes are written"); double voltage = 12; double[,] solutionMatrix = new double[currentIndex + 1, currentIndex + 1]; double[,] rightSide = new double[currentIndex + 1, 1]; //then find first nonblockdir T mach, get current index, //special case start tile int row = 0; if ( startTile.neighbors.Values.Where(neighbor => neighbor != GameTile.blockedDirectionTile) .ToList() .Count == 2) { var neighbor1 = startTile.neighbors.Values.First(neighbor => neighbor != GameTile.blockedDirectionTile); var neighbor2 = startTile.neighbors.Values.First( neighbor => neighbor != GameTile.blockedDirectionTile && neighbor != neighbor1); solutionMatrix[row, 0] = 1; solutionMatrix[row, neighbor1.currentIndex] = -1; solutionMatrix[row, neighbor2.currentIndex] = -1; rightSide[row, 0] = 0; } else { var neighbor1 = startTile.neighbors.Values.First(neighbor => neighbor != GameTile.blockedDirectionTile); solutionMatrix[row, 0] = 1; solutionMatrix[row, neighbor1.currentIndex] = -1; rightSide[row, 0] = 0; } row++; foreach (var wire in allTWires) { var neighborA = wire.neighbors.Values.First(neighbor => neighbor != GameTile.blockedDirectionTile); var neighborB = wire.neighbors.Values.First(neighbor => neighbor != GameTile.blockedDirectionTile && neighbor != neighborA); var neighborC = wire.neighbors.Values.First(neighbor => neighbor != GameTile.blockedDirectionTile && neighbor != neighborA && neighbor != neighborB); solutionMatrix[row, neighborA.currentIndex] = neighborA.firstAccessor == wire ? 1 : -1; solutionMatrix[row, neighborB.currentIndex] = neighborB.firstAccessor == wire ? 1 : -1; solutionMatrix[row, neighborC.currentIndex] = neighborC.firstAccessor == wire ? 1 : -1; rightSide[row, 0] = 0; row++; } foreach (var path in paths) { double tempResistance = 0; int tempIndex = 0; GameTile prevTile = path[0]; for (var i = 1; i < path.Count; i++) { GameTile tempTile = path[i]; if (tempTile.type != GameTileTypes.Wire.typeT) { if (tempTile.currentIndex == tempIndex) { tempResistance += tempTile.getResistanceWithDirection(prevTile); } else { solutionMatrix[row, tempIndex] = tempResistance; tempResistance = tempTile.getResistanceWithDirection(prevTile); } tempIndex = tempTile.currentIndex; } prevTile = tempTile; } rightSide[row, 0] = voltage; row++; } //specific equals case for start and end tiles. // set that 1, get other neighbors, their current indexes, 0 into solution matrix //Ideally, matrix should be square, but can be approximated if less. var amp = solutionMatrix.Solve(rightSide, leastSquares: true)[0, 0]; double totalResistance = voltage / amp; return(totalResistance); } }
private void blockOpenEnds() { // for every open end, // if wireT with only one null // put blocked direction, // else // save them in a list // then iterate board, find them, then put blockedNeighbor to its closes't wireT parent. List <GameTile> openEnds = new List <GameTile>(); startTile.neighbors[Directions.left] = GameTile.blockedDirectionTile; if (startTile.neighbors[Directions.right] == null) { startTile.neighbors[Directions.right] = GameTile.blockedDirectionTile; } if (startTile.neighbors[Directions.down] == null) { startTile.neighbors[Directions.down] = GameTile.blockedDirectionTile; } endTile.neighbors[Directions.down] = GameTile.blockedDirectionTile; if (endTile.neighbors[Directions.up] == null) { startTile.neighbors[Directions.up] = GameTile.blockedDirectionTile; } if (endTile.neighbors[Directions.left] == null) { startTile.neighbors[Directions.left] = GameTile.blockedDirectionTile; } foreach (var gameTile in board) { if (gameTile != null) { if (gameTile.type == GameTileTypes.Wire.typeT) { var nullNeighborCount = gameTile.neighbors.Count(neighbor => neighbor.Value == null); if (nullNeighborCount == 1) { var nullNeighbor = gameTile.neighbors.First(neighbor => neighbor.Value == null).Key; gameTile.neighbors[nullNeighbor] = GameTile.blockedDirectionTile; gameTile.type = GameTileTypes.Wire.typeI; // HACK, required for calculations. } else if (nullNeighborCount == 2) { openEnds.Add(gameTile); } } else { if (gameTile.neighbors.Values.Contains(null)) { openEnds.Add(gameTile); } } } } foreach (var gameTile in openEnds) { GameTile neighbor = gameTile; List <GameTile> traversed = new List <GameTile>(); do { traversed.Add(neighbor); neighbor = neighbor.neighbors.Values.First( newNeighbor => newNeighbor != null && !traversed.Contains(newNeighbor) && newNeighbor != GameTile.blockedDirectionTile); } while (neighbor.type != GameTileTypes.Wire.typeT); var beforeT = traversed.Last(); string direction = ""; foreach (var neighborPair in neighbor.neighbors) { if (neighborPair.Value == beforeT) { direction = neighborPair.Key; } } if (direction != "") { neighbor.neighbors[direction] = GameTile.blockedDirectionTile; } } }
public GameTile draw(GameTile tile, ResistilePlayer player) { return(tile.type.Contains("Wire") ? drawWire() : drawResistorSolder(player)); }
public bool IsValidMove(GameTile tile, int[] coordinates) { // Maybe keep a list of available placement coordinates // 1 Check if board has anything on that spot // 2 End is pointing off the board // 3 Check neighbors // 3.1 at least one neighbor looking to be connected // 3.2 no blocking neighbor // 3.3 has at least one neighbor // 4 if tile is on terminal spot(neighbors of end tile) // should have another connection to another tile. bool isValid = true; // Case 1 if (board[coordinates[0], coordinates[1]] != null) { return(false); } // Case 2, 3.1, 3.2 neighborCount = 0; //incremented by happyNeighbor foreach (var neighbor in tile.neighbors) { if (neighbor.Value == null) { int x = -1, y = -1; string oppositeDirection = ""; switch (neighbor.Key) { case Directions.up: x = coordinates[0]; y = coordinates[1] - 1; oppositeDirection = Directions.down; break; case Directions.left: x = coordinates[0] - 1; y = coordinates[1]; oppositeDirection = Directions.right; break; case Directions.down: x = coordinates[0]; y = coordinates[1] + 1; oppositeDirection = Directions.up; break; case Directions.right: x = coordinates[0] + 1; y = coordinates[1]; oppositeDirection = Directions.left; break; } isValid = isValid && !IsOutOfBoard(x, y) && HappyNeighbor(board[x, y], oppositeDirection); } } //Case 3.3 isValid = isValid & HasAtLeastOneNeighbor(); //Case 4 if ((coordinates[0] == xUpTerminal && coordinates[1] == yUpTerminal) || (coordinates[0] == xLeftTerminal && coordinates[1] == yLeftTerminal)) { if (neighborCount > 1) { isGameOver = true; } else { isValid = false; } } return(isValid); }