public GameNode decode(string file) { GameNode node = null; if (file == null) throw new Exception("Empty file name!"); TextAsset textAsset = (TextAsset)Resources.Load(SCRIPT_PATH + file); if (textAsset == null) throw new Exception("File not found!\nFilename: " + file); string source = textAsset.text; string pattern = "#.*\r\n"; Regex reg = new Regex(pattern); source = reg.Replace(source, ""); string[] splited = source.Split(new char[] { ';' }); node = new GameNode(splited); //for (int i = 0; i < splited.Length; i++ ) //{ // Debug.Log(splited[i]); //} return node; }
public GameNode(string[] content) { this.content = content; variableDictionary = new Dictionary<string, bool>(); labelDictionary = new Dictionary<string,int>(); next = null; current = 0; }
public override void Collide(GameNode node) { GameplayScreen.FloatingPowerupText.Score = ("+Shields"); GameplayScreen.FloatingPowerupText.StartPosition = this.Position; GameplayScreen.FloatingPowerupText.Alive = true; GameplayScreen.FloatingPowerupText.LifeSpan = 1000; base.Collide(node); }
private static int FindTileCurrentIndex(int goalNumber, GameNode current) { for (int j = 0; j < 9; j++) { if (current.Tiles[j] == goalNumber) { return j; } } return -1; }
protected static void AddSuccessor(GameNode node, ICollection<NodeInterface> result, int swapTile) { var newState = node.Tiles.Clone() as int[]; if (newState == null) return; newState[node.EmptyTileIndex] = newState[swapTile]; newState[swapTile] = 0; if (!IsEqualToParentState(node.ParentNode, newState)) result.Add(new GameNode {Tiles = newState, ParentNode = node}); }
static void Main(string[] args) { string inputFile; string outputFile; int treeDepth; string inputBoardAsAtring = "xxxxxxxxxWxxxxxxBxxxxxx"; if (args.Length < 3) { inputFile = "board1.txt"; outputFile = "board2.txt"; treeDepth = 3; } else { inputFile = args[0]; outputFile = args[1]; treeDepth = Convert.ToInt32(args[2]); } // read the board as a string from the input file inputBoardAsAtring = System.IO.File.ReadAllLines(@"" + inputFile)[0]; var board = new VariantDBoard(true, inputBoardAsAtring); Console.WriteLine(board.Print()); var movesGen = new MoveGenerator<VariantDBoard>(VariantDMoveGenerator<VariantDBoard>.Moves); var blackGen = new MoveGenerator<VariantDBoard>(VariantDMoveGenerator<VariantDBoard>.BlackMove); var root = new GameNode<VariantDBoard>(board, null, treeDepth, movesGen, blackGen, true); var minmax = new MiniMax.MiniMax<VariantDBoard>(true); var score = minmax.MiniMaxBase(root); var move = score.Item1.GetParentAtDepth(1); Console.WriteLine("Nodes generated: " + root.NumNodes() + "."); Console.WriteLine(move.Board.Print()); string[] lines = { "Board Position: " + move.Board.ToString(), "Positions evaluated by static estimation: " + minmax.StaticEvals + ".", "MINIMAX estimate: " + score.Item2 + "." }; foreach (var line in lines) { Console.WriteLine(line); } System.IO.File.WriteAllLines(@"" + outputFile, lines); }
void Awake() { if (instance == null) instance = this; decoder = new ScriptDecoder(); try { node = decoder.decode("test_script"); } catch (Exception e) { Debug.LogError(e.Message); } if (instance != this) { Destroy(gameObject); } }
public GameNode GetNearestNodeToBase(GameNode centerNode, HashSet <GameNode> baseNodes) { Queue <GameNode> nodes = new Queue <GameNode>(); nodes.Enqueue(centerNode); while (nodes.Count > 0) { var node = nodes.Dequeue(); if (!baseNodes.Contains(node)) { return(node); } foreach (var neighbour in GetNodeNeighbors(node)) { if (!neighbour.IsObstacle) { nodes.Enqueue(neighbour); } } } return(null); }
public void DynamicDeepeningSequentialTest_3() { // ARRANGE var sourceBoardStr = new[] { "b_b_", "____", "____", "_w_w" }; var sourceBoard = new BoardMock(sourceBoardStr, 4, false); var root = new GameNode(); var practiceBoard = sourceBoard.ToMinified(); var(result, maxPly) = _wrapper.Run(practiceBoard, root, sbyte.MinValue, sbyte.MaxValue, 12, _cts.Token); var bestMove = result.Peek().Move; bestMove.From.Should().BeEquivalentTo(new Cell(3, 3)); bestMove.To.Should().BeEquivalentTo(new Cell(2, 2)); }
private void MarkDestroyRec(GameNode groot) { _visited.Add(groot); foreach (GameNode neighbor in GetNeighbors(groot)) { //Debug.Log(_visited.Count); if (Equals(neighbor, null) || _visited.Contains(neighbor)) { continue; } if (groot.GetColor() == neighbor.GetColor()) { _to_destroy.Add(neighbor); if (!neighbor.IsDestroyed()) { MarkDestroyRec(neighbor); } } } }
void FindNextGame(GameNode current) { if (NextGame != null) { return; } if (current.Game.Result == Result.Undefiend && (current.Left == null || current.Left.Game.Result != Result.Undefiend) && (current.Right == null || current.Right.Game.Result != Result.Undefiend)) { NextGame = current; return; } if (current.Left != null && current.Left.Game.Result == Result.Undefiend) { FindNextGame(current.Left); } if (current.Right != null && current.Right.Game.Result == Result.Undefiend) { FindNextGame(current.Right); } }
public NodeVisualiser(Zone zone, GameNode currentNode) : this() { Visualiser = this; _sysEvent = true; try { _zone = zone; rbWorld.Checked = (zone == null); rbZone.Checked = !rbWorld.Checked; zoneComboBox.SelectedItem = zone; if (currentNode != null) { cbSelected.SelectedItem = currentNode; } DisplayMap(); } finally { _sysEvent = false; } }
private Pen OnGetLinkPen(GameNode source, object link) { if ((waypointLinkBindingSource.DataSource != null) && (waypointLinkBindingSource.Count > 0)) { List <WaypointLink> path = (List <WaypointLink>)waypointLinkBindingSource.DataSource; //see if this link is present. GameNode target = null; if (link is TransportLink) { target = ((TransportLink)link).Destination; } else { target = ((GameNodeLink)link).Target; } if (target != null) { bool found = false; foreach (var join in path) { if (((join.Source.Node == source) && (join.Destination.Node == target)) || ((join.Source.Node == target) && (join.Destination.Node == source))) { found = true; break; } } if (found) { return(new Pen(Color.Aquamarine, 3)); } } } return((link is TransportLink) ? _mapSettings.TeleportLinkPen : _mapSettings.MovementLinkPen); }
public void DynamicTreeSplittingSearchTest_4() { // ARRANGE var sourceBoardStr = new[] { "___b__", "______", "_b____", "______", "_b_b__", "__w___" }; var sourceBoard = new BoardMock(sourceBoardStr, 6, false); var root = new GameNode(); var practiceBoard = sourceBoard.ToMinified(); _search.Search(root, 3, sbyte.MinValue, sbyte.MaxValue, practiceBoard, _cts.Token); var bestMove = root.GetBestMove(); bestMove.Should().BeEquivalentTo(new Move(2, 5, 4, 3)); }
public bool CheckNodeToJump(GameNode node) { bool check = false; if (CheckNodeState(node)) { if (node == _currentNode.parent) { check = true; } else { foreach (GameNode _node in _currentNode.junctions) { if (_node == node) { check = true; } } } } return(check); }
public void GameTreeSequentialSearch_5() { // ARRANGE var sourceBoardStr = new[] { "__b___", "______", "__b___", "______", "__b_b_", "___w__" }; var sourceBoard = new BoardMock(sourceBoardStr, 6, false); var root = new GameNode(); var practiceBoard = sourceBoard.ToMinified(); _search.Search(root, 2, sbyte.MinValue, sbyte.MaxValue, practiceBoard, _cts.Token); var bestMove = root.GetBestMove(); bestMove.Should().BeEquivalentTo(new Move(3, 5, 1, 3)); }
private Brush OnGetNodeBrush(GameNode node) { if (node == _selectedNode) { return(Brushes.DeepSkyBlue); } if (node == cbSelected.SelectedItem) { return(Brushes.Chartreuse); } if (node == cbTarget.SelectedItem) { return(Brushes.LightCoral); } if (node == _startNode) { return(Brushes.Pink); } if (node == _endNode) { return(Brushes.Red); } return(_mapSettings.NodeBrush); }
private GameObject createLine(GameNode origen, GameNode destino) { Vector3 vo = origen.transform.position; Vector3 vd = destino.transform.position; GameObject go = new GameObject(); go.name = origen.Info.nodeName.ToString() + " to " + destino.Info.nodeName.ToString(); Debug.Log(go.name); LineRenderer r = go.AddComponent <LineRenderer>(); r.material = new Material(Shader.Find("Sprites/Default")); Color color = Color.red; r.startColor = color; r.endColor = color; r.startWidth = 0.08f; r.endWidth = 0.08f; List <Vector3> poss = new List <Vector3>(); poss.Add(vo); poss.Add(vd); r.SetPositions(poss.ToArray()); return(go); }
private void CheckForInput() { if (Input.GetMouseButtonDown(0) && !mouseOnUIElement) { // Vector3 rayStartingPos = cameraRef.transform.position; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.Log("Mouse click"); // if (Physics.Raycast(rayStartingPos, cameraRef.transform.forward, out RaycastHit hit, interactableLayer)) if (Physics.Raycast(ray, out RaycastHit hit, 666)) { Debug.Log("Mouse click with ray"); if (hit.transform.gameObject.CompareTag("GameNode")) { Debug.Log("Game Node Clicked"); GameNode temp = hit.transform.gameObject.GetComponent <GameNode>(); if (startSetted && finishSetted) { start = temp; finishSetted = false; } else if (startSetted && !finishSetted) { end = temp; finishSetted = true; } else if (!startSetted && !finishSetted) { start = temp; startSetted = true; } ChangeMarkersPosition(); } } } }
private void DropNodes() { GameNode curr_node = null; GameNode lower_node = null; int new_indy = 0; for (int row_indy = _map_height - 2; row_indy >= 0; row_indy--) { for (int col_indy = _map_width - 1; col_indy >= 0; col_indy--) { curr_node = _map[row_indy, col_indy]; if (Equals(curr_node, null)) { continue; } new_indy = row_indy + 1; lower_node = _map[new_indy, col_indy]; Debug.LogFormat("{0}", curr_node); while (Equals(lower_node, null) || lower_node.IsDestroyed()) { _map[new_indy, col_indy] = curr_node; _map[new_indy - 1, col_indy] = null; new_indy = new_indy + 1; if (new_indy == _map_height) { break; } lower_node = _map[new_indy, col_indy]; Debug.Log(this); } } } }
public void SetNeighbor(GameNode new_neighbor, NeighborDirection direction) { neighbors[(int)direction] = new_neighbor; new_neighbor.GetNeighbors()[(int)AntiDirection(direction)] = this; }
private void ctrlGameNodeSelector1_OnNodeSelected(object sender, GameNode node) { btnOK.PerformClick(); }
public bool CheckNodeState(GameNode node) { return(node.State == GameNode.NodeState.Open); }
private void Start() { GameNode = GetNode <Node>("/root/Game") as Game; GameNode.Start(); Player = GameNode.GetNode <KinematicBody2D>("Player"); }
// Use this for initialization void Start() { GameNode SW = create_diamond(5); print_diamond(SW); }
public void RemoveInputNode(GameNode node) { if(inputNodes.Contains(node) == true) { // print (string.Format("Removing {0} to {1}'s input nodes",node.NodeValue.ToString(),this.name)); inputNodes.Remove(node); } }
/// <summary> /// This virtual method is to contain the translation of the movable element in the given direction /// </summary> /// <param name="direction">Direction along which move the movable element</param> virtual public void Move(Vector3 direction) { GameNode.Translate(direction); //physObj.Velocity = 100 * direction; }
protected override void LoadModel() { gameEntity = mSceneMgr.CreateEntity("CannonGun.mesh"); GameNode = mSceneMgr.CreateSceneNode(); GameNode.AttachObject(gameEntity); }
/// <summary> /// This method moves the model element in the specified direction /// </summary> /// <param name="direction">A direction in which to move the model element</param> public override void Move(Vector3 direction) { GameNode.Translate(direction); }
/// <summary> /// This modeto rotate the model element as described by the quaternion given as parameter in the /// specified transformation space /// </summary> /// <param name="quaternion">The quaternion which describes the rotation axis and angle</param> /// <param name="transformSpace">The space in which to perfrom the rotation, local by default</param> public override void Rotate(Quaternion quaternion, Node.TransformSpace transformSpace = Node.TransformSpace.TS_LOCAL) { GameNode.Rotate(quaternion, transformSpace); }
public void AddGameNode(GameNode gameNode) { gameNodes.Add(gameNode); }
/// <summary> /// This method adds a child to the node of this model element /// </summary> /// <param name="childNode"></param> public void AddChild(SceneNode childNode) { GameNode.AddChild(childNode); }
private void SwitchNode() { this.node = this.node.NextNode(); }
private void gotoNextScript(string nextScript) { Debug.Log("goto script: " + nextScript); node = decoder.decode(nextScript); }
public GameNode AddRight(GameNode node) { Right = node; node.NodeParent = this; return(this); }
public void AddInputNode(GameNode value) { if(inputNodes.Contains(value) == false) { inputNodes.Add(value); SolverCheck.Instance.CheckSolve(); } }
public GameNode AddLeft(GameNode node) { Left = node; node.NodeParent = this; return(this); }
public void CreateMap() { if (NodeCount == 0) { NodeCount = Profile.Instance().Level *5; } if (_maxStep == 0) { _maxStep = (int)(NodeCount * 1.5 + 5); } _map.Place_random_nodes(NodeCount, Shuffle); _map.Calc_neighbors(); _map.Trace_astar_wave(); foreach (var ynodes in _map.nodes.Values) { foreach (var node in ynodes.Values) { GameObject no = Instantiate(NODE); _visualize.Add(no); GameNode game_node = no.GetComponent <GameNode>(); game_node.x = node.x; game_node.y = node.y; game_node.w = node.w; GameNodes.Add(new Vector2Int(node.x, node.y), game_node); float random_pos = 0f; random_pos = Random.Range(-1f, 5f); float random_pos_z = 0f; random_pos_z = Random.Range(-1f, 5f); no.transform.position = new Vector3(node.x * 5 + Random.Range(RandomPoz.x, RandomPoz.y), node.y * 5 + Random.Range(RandomPoz.x, RandomPoz.y), 0); no.name = "X: " + node.x + " Y: " + node.y + " W: " + node.w; if (node.x == 0 && node.y == 0) { Game.Instance().SetCurrentNode(game_node); } else { game_node.Status = GameNode.NodeStatus.Uncnown; } } } foreach (var ynodes in _map.nodes.Values) { foreach (var node in ynodes.Values) { GameNode _final_node = null; GameNodes.TryGetValue(new Vector2Int(node.x, node.y), out _final_node); //int _lineRenderCount = 0; if (_final_node == null) { continue; } if (node.neighbors.Count > 0) { foreach (Node n in node.neighbors) { GameNode _neighbors_node = null; GameNodes.TryGetValue(new Vector2Int(n.x, n.y), out _neighbors_node); _final_node.neighbors.Add(_neighbors_node); } } if (node.junctions.Count > 0) { foreach (Node n in node.junctions) { GameNode _junctions_node = null; GameNodes.TryGetValue(new Vector2Int(n.x, n.y), out _junctions_node); _final_node.junctions.Add(_junctions_node); //LineRenderer _line = _final_node._lines[_lineRenderCount]; //_line.SetPosition(0, _final_node.transform.position); //_line.SetPosition(1, _junctions_node.transform.position); //_lineRenderCount++; } } if (node.parent != null) { GameNode _parant_node = null; GameNodes.TryGetValue(new Vector2Int(node.parent.x, node.parent.y), out _parant_node); _final_node.parent = _parant_node; } } } if (Game.Instance().Alldatacount == 0) { Game.Instance().Alldatacount = NodeCount * 10; } CorrectJunctions(JoinChance); StartCoroutine(CreateNodeType()); // StartCoroutine(SetVisual()); }
public void CarSpawned(GameObject car, GameNode target, GameNode source) { _cars.Add(car.GetComponent<Car>()); }
public void SpawnCar(GameNode node) { GameObject.Instantiate(CarPrefab, node.transform.position, node.transform.rotation); }
public void Clean() { DestroyAllChildren(evolutionsParent); currentNode = null; OpenBasicShop(); }