IEnumerator StopNodeEvent(int remainingMoves, int dir, float movementSpeed) { BoardNode curBoardNode = currentNode.GetComponent <BoardNode>(); //stop node logic/////////////////////////////////////////////////////////////////////////////////////////////// if (curBoardNode.nodeType == BoardNode.NodeType.stop && curBoardNode.isCompleted == false) { //anim.SetBool("isWalking", false); isMoving = false; curBoardNode.timelinePlaybackManager.currentPlayer = this; curBoardNode.timelinePlaybackManager.timelines[0].Play(); while (!eventComplete) { yield return(null); } eventComplete = false; /////////reset value for next time yield return(new WaitForSeconds(1f)); /////// event fail if (chanceEventSuccess == false) { StartCoroutine(MovePlayer(1, -1, 3f)); } ////// event success else { curBoardNode.roadBlock.gameObject.SetActive(false); curBoardNode.isCompleted = true; StartCoroutine(MovePlayer(remainingMoves, dir, movementSpeed)); } } }
public List <BoardNode> GetNeighbours(BoardNode node) { List <BoardNode> neighbours = new List <BoardNode>(); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { if (x == 0 && y == 0) { continue; } //Remove for diagonals if (y == x * -1 || x == y * -1 || x == y) { continue; } int checkX = node.gridIndex.x + x; int checkY = node.gridIndex.y + y; if (checkX >= 0 && checkX < Data.instance.currBoard.boardSize.x && checkY >= 0 && checkY < Data.instance.currBoard.boardSize.y) { neighbours.Add(grid[checkX, checkY]); } } } return(neighbours); }
//Note: A move (this class) is deficed by the selected piece, the selected destination for said piece and a value for the move. /// <summary> /// Mainline Method: Gets the child moves of this current one. /// </summary> /// <param name="owner">Which user are we used from?</param> /// <returns>A list of moves</returns> public List <Move> Expand(UserModel owner, ref List <BoardPiece> simulatedBoard) { List <Move> output = new List <Move> (); for (int i = 0; i < owner.OwnedPieces.Count; i++) { BoardPiece piece = owner.OwnedPieces[i]; List <Vector2Int> path = owner.FindPotentialPaths(piece.pos, new List <Vector2Int> (), true); for (int a = 0; a < path.Count; a++) { //Simulate a board simulatedBoard = test_OriginalBoard.Clone(); int newPiece = 0; for (int p = 0; p < simulatedBoard.Count; p++) { if (simulatedBoard[p].pos == piece.pos) { newPiece = p; break; } } Vector2Int currentPiece = simulatedBoard[newPiece].pos; Vector2Int target = path[a]; owner.Simulate_MovePiece(newPiece, target, simulatedBoard); BoardNode goal = owner.DesiredGoal(); float value = EvaluateMove(simulatedBoard, owner, goal); Move move = new Move(currentPiece, target, value); output.Add(move); } //Return the list. } return(output); }
public static NodeRow GetNodeRow(List <BoardNode> nodes, float x, float y) { List <MonoBehaviour> behaviorList = new List <MonoBehaviour> (); foreach (var n in nodes) { behaviorList.Add(n.Behavior); } var row = GetBehaviorRow(behaviorList, x, y); List <BoardNode> hidden = new List <BoardNode> (); foreach (var b in row.Hidden) { hidden.Add(((BoardNodeBehavior)b).Node); } BoardNode closest = null; try { closest = ((BoardNodeBehavior)row.Closest).Node; } catch (System.Exception) { } return(new NodeRow(closest, hidden)); }
/// <summary> /// Mainline method: Creates a hexagon grid. /// </summary> /// <param name="blueprint">The size as well as the type of elements included in the grid.</param> /// <param name="prefab">A prefab reference to create said grid.</param> /// <returns>A 2D array of the hexagon grid.</returns> public static TestBoardModel.Board CreateHexagonGrid(int[,] blueprint, NodeObject prefab) { Transform parent = CreateCanvas($"{prefab.name}'s list."); Board newBoard = new TestBoardModel.Board(blueprint.GetLength(0), blueprint.GetLength(1)); globalNodeViewList = new List <NodeObject>(); int xPos; for (int x = 0; x < blueprint.GetLength(0); x++) { for (int y = 0; y < blueprint.GetLength(1); y++) { xPos = y - x / 2; Team currentTeam = (blueprint[x, y] > 8 && blueprint[x, y] != 11) ? (blueprint[x, y] == 14 || blueprint[x, y] == 19) ? Team.BigRed : (blueprint[x, y] == 16 || blueprint[x, y] == 17) ? Team.BigGreen : Team.Unoccupied : (Team)blueprint[x, y]; //O: Massive condition to limit only the bigRed and bigGreen to be used when nessesary. Vector2Int boardPos = new Vector2Int(x, y); Vector2 objectPos = SetPosition(new Vector2Int(x, xPos) - new Vector2(newBoard.GetLength(0) / centerPointX, newBoard.GetLength(1) / centerPointY)); //Like here (O) newBoard[x, y] = new BoardNode(boardPos, objectPos, currentTeam); //The NodeObject uses the raw information to set its proper color on the node. globalNodeViewList.Add(NodeObject.CreateNodeObject(prefab, objectPos, (NodeColor)blueprint[x, y], parent, boardPos)); } } return(newBoard); }
protected override void OnEnergyEnter(EnergyBehavior energyBehavior) { var row = ParentBoard.GetNotNodes(Behavior.transform.position.x, Behavior.transform.position.y); BoardNode closest = null; if (row.Count == 1) { closest = row[0]; } else { float closestDist = float.MaxValue; foreach (var n in row) { float dist = Vector3.Distance(Behavior.transform.position, n.Behavior.transform.position); if (closest == null || dist < closestDist) { closestDist = dist; closest = n; } } } if (closest != null) { DeferEnergyEnterTo(closest, energyBehavior); } }
public void SendEnergy(BoardNode to) { if (CanSend && to.CanReceive) { Behavior.StartCoroutine(DoSendEnergy(to)); } }
/**************************************************************************** * Makes isTrap true if the oponent is setting a trap on any given direction * * * * The "Trap Pattern" is depicted below: * * * * (Empty Move Node)->(Oponent Node)->(Oponent Node)->(Empty Node) * ****************************************************************************/ void BlocksTrap(BoardNode curNode, int direction, ref int count, ref bool isTrap) { if (curNode == null) { return; } if (curNode.token == COMPUTER) { count++; if (curNode.neighbors[direction] != null) { if (count == 2 && curNode.neighbors[direction].token == EMPTY) { isTrap = true; return; } } BlocksTrap(curNode.neighbors[direction], direction, ref count, ref isTrap); } else { return; } }
// Returns best score found for current player private static int MiniMaxSearch(BoardNode currentNode, int player, int depth, int a, int b) { if (MainClass.timesUp) { return(0); // Will not be used as this whole iteration is aborted } // End game if max depth reached or game is over if (depth == maxDepth || currentNode.eval.boardState != BoardState.ongoing) { return(currentNode.eval.score); } // Create and evaluate children List <BoardNode> boardNodes = new List <BoardNode>(); foreach (int move in currentNode.board.GetPossibleMoves()) { Con4Board nextBoard = currentNode.board.SimulateMove(player, move); Evaluation nextEval = CalculateBoardScore(nextBoard, depth + 1); boardNodes.Add(new BoardNode { board = nextBoard, eval = nextEval }); } // Orden them, most promising first if (player == MAXIMIZING) { boardNodes = boardNodes.OrderByDescending(x => x.eval.score).ToList(); } else { boardNodes = boardNodes.OrderBy(x => x.eval.score).ToList(); } int searchScore = player == MAXIMIZING ? int.MinValue : int.MaxValue; foreach (BoardNode boardNode in boardNodes) { if (player == MAXIMIZING) { searchScore = Math.Max(searchScore, MiniMaxSearch(boardNode, MINIMIZING, depth + 1, a, b)); a = Math.Max(a, searchScore); if (a >= b) { break; } } else { searchScore = Math.Min(searchScore, MiniMaxSearch(boardNode, MAXIMIZING, depth + 1, a, b)); b = Math.Min(b, searchScore); if (b <= a) { break; } } } return(searchScore); }
public static BoardNode UnApplyMoveFromBoard(BoardNode currentBoardNode) { var previousState = currentBoardNode.Node.Previous; var unDoneBoard = currentBoardNode.Board.UnapplyMoveFromBoard((BoardState)previousState.Value.BoardState, currentBoardNode.Node.Value.MoveValue); return(new BoardNode(unDoneBoard, previousState)); }
public void Travel(BoardNode from, BoardNode to) { Affiliation = from.Affiliation; Origin = from; Destination = to; Behavior.transform.position = from.Behavior.transform.position; Behavior.TravelTo(to); }
public void AddChild(BoardNode _child) { if (endNode == true) { endNode = false; } childNodes.Add(_child); }
/// <summary> /// Acts similarly to normal alpha beta search but instead of generating new board nodes, traverses existing board node list. /// </summary> /// <param name="_node"></param> /// <param name="_depth"></param> /// <param name="_alpha"></param> /// <param name="_beta"></param> /// <param name="_searchingPlayer"></param> /// <param name="_maximizingPlayer"></param> /// <param name="_player"></param> /// <param name="_accuracyMod"></param> /// <returns></returns> static public float TraverseNodeList(BoardNode _node, int _depth, float _alpha, float _beta, int _searchingPlayer, bool _maximizingPlayer, AI _player, float _accuracyMod) { float v; if (_depth == 0 || _node.MoveCount() == 0) { if (_maximizingPlayer) { v = (float)_node.GetValue(_player); if (_accuracyMod != 0) { System.Random random = new MathNet.Numerics.Random.SystemRandomSource(); v = v + (float)random.NextDouble() * (2 * _accuracyMod) - _accuracyMod; } return(v); } else { return(AlphaBeta(_node, _depth, _alpha, _beta, _searchingPlayer, _maximizingPlayer, _player, _accuracyMod)); } } if (!_node.IsEndNode()) { if (_maximizingPlayer) { v = -Mathf.Infinity; foreach (BoardNode b in _node.GetChildren()) { v = Mathf.Max(v, TraverseNodeList(b, _depth - 1, _alpha, _beta, _searchingPlayer, false, _player, _accuracyMod)); _alpha = Mathf.Max(_alpha, v); if (_beta <= _alpha) { break; } } return(v); } else { v = 1; foreach (BoardNode b in _node.GetChildren()) { v = Mathf.Min(v, TraverseNodeList(b, _depth - 1, _alpha, _beta, _searchingPlayer, true, _player, _accuracyMod)); _beta = Mathf.Min(_beta, v); if (_beta <= _alpha) { break; } } return(v); } } else { return(AlphaBeta(_node, _depth, _alpha, _beta, _searchingPlayer, _maximizingPlayer, _player, _accuracyMod)); } }
int CountComputerTokensDiagonalTwo(BoardNode moveNode) { int count = 0; TraverseAndCountTokens(moveNode.neighbors[upR], upR, COMPUTER, ref count); TraverseAndCountTokens(moveNode.neighbors[downL], downL, COMPUTER, ref count); return(count); }
int CountOpponentTokensVertical(BoardNode moveNode) { int count = 0; TraverseAndCountTokens(moveNode.neighbors[up], up, OPONENT, ref count); TraverseAndCountTokens(moveNode.neighbors[down], down, OPONENT, ref count); return(count); }
int CountComputerTokensHorizontal(BoardNode moveNode) { int count = 0; TraverseAndCountTokens(moveNode.neighbors[L], L, COMPUTER, ref count); TraverseAndCountTokens(moveNode.neighbors[R], R, COMPUTER, ref count); return(count); }
int[] Move() { CountAndAssignNodeScores(); BoardNode optimumMove = FindHighestScoringNode(); return(new int[2] { optimumMove.row, optimumMove.col }); }
int CountComputerTokensVertical(BoardNode moveNode) { int count = 0; TraverseAndCountTokens(moveNode.neighbors[up], up, COMPUTER, ref count); TraverseAndCountTokens(moveNode.neighbors[down], down, COMPUTER, ref count); return(count); }
int CountOpponentTokensDiagonalTwo(BoardNode moveNode) { int count = 0; TraverseAndCountTokens(moveNode.neighbors[upR], upR, OPONENT, ref count); TraverseAndCountTokens(moveNode.neighbors[downL], downL, OPONENT, ref count); return(count); }
public static BoardNode ApplyMoveToBoard(BoardNode board, Move moveToApply) { var postMoveBoard = board.Board.ApplyMoveToBoard(moveToApply); var san = moveToSan.Translate(moveToApply, board.Board, postMoveBoard); var postMoveState = new PostMoveState(postMoveBoard, moveToApply, san); var node = new MoveTreeNode <PostMoveState>(postMoveState, board.Node); return(new BoardNode(postMoveBoard, node)); }
int CountOpponentTokensHorizontal(BoardNode moveNode) { int count = 0; TraverseAndCountTokens(moveNode.neighbors[L], L, OPONENT, ref count); TraverseAndCountTokens(moveNode.neighbors[R], R, OPONENT, ref count); return(count); }
void ApplyAtmosphericDiffusion() { BoardNode[, ] board_after = new BoardNode[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { BoardNode old = board[x, y]; // If a tile is on the edge, it's starting condition is weighed more (since there isn't diffusion from off the board). float edges = 0; if (x == 0 || x == width - 1) { edges++; } if (y == 0 || y == height - 1) { edges++; } // I don't understand why this isn't 4. float newMoisture = old.moisture * (1f - (3.5f - edges) * ATMOSPHERIC_DIFFUSION); float newTemperature = old.temperature * (1f - (3.5f - edges) * ATMOSPHERIC_DIFFUSION); if (x > 0) { newMoisture += board[x - 1, y].moisture * ATMOSPHERIC_DIFFUSION; newTemperature += board[x - 1, y].temperature * ATMOSPHERIC_DIFFUSION; } if (x < width - 1) { newMoisture += board[x + 1, y].moisture * ATMOSPHERIC_DIFFUSION; newTemperature += board[x + 1, y].temperature * ATMOSPHERIC_DIFFUSION; } if (y > 0) { newMoisture += board[x, y - 1].moisture * ATMOSPHERIC_DIFFUSION; newTemperature += board[x, y - 1].temperature * ATMOSPHERIC_DIFFUSION; } if (y < height - 1) { newMoisture += board[x, y + 1].moisture * ATMOSPHERIC_DIFFUSION; newTemperature += board[x, y + 1].temperature * ATMOSPHERIC_DIFFUSION; } board_after[x, y] = new BoardNode(old.altitude, (int)newMoisture, (int)newTemperature, old.wind); } } board = board_after; if (display != null) { display.DrawBoard(board); } }
public void NodeClicked(BoardNode node) { if (node == null) { currentOrb = null; hideSelection(); return; } if (currentOrb == node) { currentOrb = null; hideSelection(); return; } Orb nodeOrb = node as Orb; if (nodeOrb != null) { currentOrb = nodeOrb; showSelection(currentOrb.transform.position); return; } if (currentOrb != null) { if (node.posX == currentOrb.posX) { if (node.posY > currentOrb.posY) { currentOrb.moveUp(); } else if (node.posY < currentOrb.posY) { currentOrb.moveDown(); } } else if (node.posY == currentOrb.posY) { if (node.posX > currentOrb.posX) { currentOrb.moveRight(); } else if (node.posX < currentOrb.posX) { currentOrb.moveLeft(); } } } currentOrb = null; hideSelection(); }
/******************************************************************************** * Creates board network nodes reflecting the gameBoard passed in as a parameter * ********************************************************************************/ void CreateBoardNodes(Board gameBoard) { int[,] boardMatrix = gameBoard.getGameMatrix(); for (int r = 0; r < NUM_ROW; r++) { for (int c = 0; c < NUM_COL; c++) { boardNetwork[r, c] = new BoardNode(boardMatrix[r, c], r, c); } } }
/* * Vector2Int[] SimplifyPath(List<BoardNode> path) * { * List<Vector3> waypoints = new List<Vector3>(); * * // adds the actual point of contact! * waypoints.Add(grid.NodeFromWorldPoint(endGoal).worldPosition); * // * Vector2 directionOld = Vector2.zero; * for (int i = 1; i < path.Count; i++) * { * Vector2 directionNew = new Vector2(path[i - 1].gridX - path[i].gridX, path[i - 1].gridY - path[i].gridY); * if (directionNew != directionOld) * { * waypoints.Add(path[i].worldPosition); * * } * directionOld = directionNew; * } * return waypoints.ToArray(); * } * //*/ int GetDistance(BoardNode nodeA, BoardNode nodeB) { int distX = Mathf.Abs(nodeA.gridIndex.x - nodeB.gridIndex.x); int distY = Mathf.Abs(nodeA.gridIndex.y - nodeB.gridIndex.y); if (distX > distY) { return(14 * distY + 10 * (distX - distY)); } return(14 * distX + 10 * (distY - distX)); }
public PossibleMove AlphaBeta (BoardNode node, int depth, PossibleMove alpha, PossibleMove beta, bool maximizingPlayer) { if (depth == 0) // || node.IsLeaf) { // Debug.Log("node._move[0] = " + node._move.x); // test node collection here { return(new PossibleMove(node._move.x, node._move.y, BoardNode.GetHeuristicValue(node, depth))); } if (maximizingPlayer == true) { // Debug.Log("Max"); List <PossibleMove> childs = CheckLegalMoves(node._bData, 1); // List<BoardNode> children = BoardNode.GetChildren(node, 1); PossibleMove score; foreach (PossibleMove kid in childs) { var bn = BoardNode.GetChild(node._bData, kid, 1); score = AlphaBeta(bn, depth - 1, alpha, beta, !maximizingPlayer); alpha = alpha.score == Mathf.Max(alpha.score, score.score) ? alpha : score; alpha.x = kid.x; alpha.y = kid.y; if (beta.score <= alpha.score) { break; // beta cut-off } } // Debug.Log("alpha = " + alpha.score); return(alpha); } else { // Debug.Log("Min"); List <PossibleMove> childs = CheckLegalMoves(node._bData, 0); // List<BoardNode> children = BoardNode.GetChildren(node, 0); PossibleMove score; foreach (PossibleMove kid in childs) { var bn = BoardNode.GetChild(node._bData, kid, 0); score = AlphaBeta(bn, depth - 1, alpha, beta, !maximizingPlayer); beta = beta.score == Mathf.Min(beta.score, score.score) ? beta : score; // beta = min(beta,score) beta.x = kid.x; beta.y = kid.y; if (beta.score <= alpha.score) { break; // alpha cut-off } } // Debug.Log("beta = " + beta.score); return(beta); } }
public BoardNode CreateNode(BoardNodeData data, Board parent) { GameObject prefab = null; BoardNode node = null; #pragma warning disable 0162 // Unreachable code switch (data.Type) { case BoardNodeType.Basic: prefab = BasicBoardNodePrefab; node = new BasicBoardNode(data, parent); break; case BoardNodeType.Drain: prefab = DrainBoardNodePrefab; node = new DrainBoardNode(data, parent); break; case BoardNodeType.Fill: prefab = FillBoardNodePrefab; node = new FillBoardNode(data, parent); break; case BoardNodeType.Null: prefab = NullBoardNodePrefab; node = new NullBoardNode(data, parent); break; case BoardNodeType.Pool: prefab = PoolBoardNodePrefab; node = new PoolBoardNode(data, parent); break; case BoardNodeType.Redirect: prefab = RedirectBoardNodePrefab; node = new RedirectBoardNode(data, parent); break; case BoardNodeType.Vortex: prefab = VortexBoardNodePrefab; node = new VortexBoardNode(data, parent); break; } #pragma warning restore 0162 var nodeObj = GameObject.Instantiate(prefab) as GameObject; var behavior = nodeObj.GetComponent <BoardNodeBehavior>(); node.AttachedToBehavior(behavior); behavior.AttachToNode(node); return(node); }
public static BoardNode[,] MakeBoard(Data_Board boardData) { // Debug.Log("Offset >> " + (-(boardData.boardSize.x / 2f)) + " , " + (-(boardData.boardSize.y / 2f))); Transform holder = new GameObject("Board").GetComponent <Transform>(); BoardNode[,] boardGameplay = new BoardNode[boardData.boardSize.x, boardData.boardSize.y]; BoardTile[,] boardVisual; switch (boardData.boardType) { case BoardType.Circle: boardVisual = Board_Circle.MakeBoard(boardData.boardSize, boardData.secondaryFloat); break; default: boardVisual = Board_Default.MakeBoard(boardData.boardSize); break; } //float xS = -(boardVisual.GetLength(1) / 2f); // float yS = -(boardVisual.GetLength(0) / 2f); // Vector2 startPos = new Vector2(yS * tileSize, xS * tileSize); for (int x = 0; x < boardVisual.GetLength(0); x++) { for (int y = 0; y < boardVisual.GetLength(1); y++) { Vector2 location = IndexToPos(new Vector2Int(boardVisual.GetLength(0), boardVisual.GetLength(1)), new Vector2Int(x, y)); //new Vector2(startPos.x + (tileSize * x), startPos.y + (tileSize * y)); SpriteRenderer temp = GameObject.Instantiate(Data.instance.tileObj, location, Quaternion.Euler(new Vector3(0, 0, boardVisual[x, y].rotation)), holder).GetComponent <SpriteRenderer>(); temp.color = (x + y) % 2 == 0 ? Data.instance.artData.tileBlack : Data.instance.artData.tileWhite; if (temp.GetComponentInChildren <TextMeshPro>() != null) { temp.GetComponentInChildren <TextMeshPro>().text = x + "," + y; } //init node boardGameplay[x, y] = new BoardNode(x, y); boardGameplay[x, y].areaType = boardVisual[x, y].areaType; // switch (boardVisual[x, y].areaType) { case BoardArea.Corner: temp.sprite = Data.instance.artData.corner; break; case BoardArea.Edge: temp.sprite = Data.instance.artData.edge; break; case BoardArea.Middle: temp.sprite = Data.instance.artData.middle; break; case BoardArea.Empty: temp.color = Data.instance.artData.tileBlock; boardGameplay[x, y].unitObj = temp.gameObject.AddComponent <Unit_Block>(); break; } } } return(boardGameplay); }
BoardNode FindHighestScoringNode() { BoardNode highestNode = possibleMoves.First(); foreach (var moveNode in possibleMoves) { if (moveNode.score > highestNode.score) { highestNode = moveNode; } } return(highestNode); }
public Collectable Spawn(BoardNode n) { PlatformNode pn; if (n.TryGetComponent(out pn)) { transform.position = n.landingPosition.position; currentNode = pn; return(this); } SpawnerManager.Despawn(this); return(null); }
void AssignOffensivePoints(BoardNode moveNode, int count) { if (count == 1) { moveNode.score += 0.15; } else if (count == 2) { moveNode.score += 0.15; } else if (count == 3) { moveNode.score += 1.0; } else if (count == 4) { moveNode.score += 2.0; } else if (count == 5) { moveNode.score += 1; } }
void AssignTrapBlockingPoints(BoardNode moveNode) { double trapBlockingPoints = 0; int count; bool isTrap; for (int direction = 0; direction < 8; direction++) { count = 0; isTrap = false; BlocksTrap(moveNode.neighbors[direction], direction, ref count, ref isTrap); if (isTrap) { trapBlockingPoints += 0.25; } } moveNode.score += trapBlockingPoints; }
int CountComputerTokensDiagonalTwo(BoardNode moveNode) { int count = 0; TraverseAndCountTokens(moveNode.neighbors[upR], upR, COMPUTER, ref count); TraverseAndCountTokens(moveNode.neighbors[downL], downL, COMPUTER, ref count); return count; }
int CountComputerTokensHorizontal(BoardNode moveNode) { int count = 0; TraverseAndCountTokens(moveNode.neighbors[L], L, COMPUTER, ref count); TraverseAndCountTokens(moveNode.neighbors[R], R, COMPUTER, ref count); return count; }
int CountComputerTokensVertical(BoardNode moveNode) { int count = 0; TraverseAndCountTokens(moveNode.neighbors[up], up, COMPUTER, ref count); TraverseAndCountTokens(moveNode.neighbors[down], down, COMPUTER, ref count); return count; }
int CountOpponentTokensDiagonalTwo(BoardNode moveNode) { int count = 0; TraverseAndCountTokens(moveNode.neighbors[upR], upR, OPONENT, ref count); TraverseAndCountTokens(moveNode.neighbors[downL], downL, OPONENT, ref count); return count; }
int CountOpponentTokensHorizontal(BoardNode moveNode) { int count = 0; TraverseAndCountTokens(moveNode.neighbors[L], L, OPONENT, ref count); TraverseAndCountTokens(moveNode.neighbors[R], R, OPONENT, ref count); return count; }
int CountOpponentTokensVertical(BoardNode moveNode) { int count = 0; TraverseAndCountTokens(moveNode.neighbors[up], up, OPONENT, ref count); TraverseAndCountTokens(moveNode.neighbors[down], down, OPONENT, ref count); return count; }
/************************************************************************************************************ * Traverses the board from the give start node in the direction provided and counts the desired tokens. It * * counts the number of such tokens in a row and it will stop if it finds a different token or an empty node * ************************************************************************************************************/ void TraverseAndCountTokens(BoardNode curNode, int direction, int TOKEN, ref int count) { if (curNode == null) { return; } if (curNode.token == TOKEN) { count++; TraverseAndCountTokens(curNode.neighbors[direction], direction, TOKEN, ref count); } else { return; } }
void AssignDefensivePoints(BoardNode moveNode, int count) { if (count == 1) { moveNode.score += 0.05; } else if (count == 2) { moveNode.score += 0.25; } else if (count == 3) { moveNode.score += 5.0; } else if (count == 4) { moveNode.score += 8.0; } else if (count == 5) { moveNode.score += 10.0; } }