Exemplo n.º 1
0
        public void FindMoves_ReturnsExpectedNodesForMovementThree()
        {
            BoardGraph     boardGraph     = new BoardGraph();
            MoveCalculator moveCalculator = new MoveCalculator();

            List <Node> occupiedNodes = new List <Node>();

            occupiedNodes.Add(boardGraph.Nodes[13]);
            occupiedNodes.Add(boardGraph.Nodes[14]);
            occupiedNodes.Add(boardGraph.Nodes[17]);
            occupiedNodes.Add(boardGraph.Nodes[18]);
            occupiedNodes.Add(boardGraph.Nodes[19]);
            occupiedNodes.Add(boardGraph.Nodes[20]);
            occupiedNodes.Add(boardGraph.Nodes[23]);
            occupiedNodes.Add(boardGraph.Nodes[24]);

            IEnumerable <NodePath> actual;

            actual = moveCalculator.FindMoves(boardGraph.Nodes[13], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[14], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[17], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[18], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[19], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[20], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[23], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[24], 3, occupiedNodes);
        }
Exemplo n.º 2
0
        public void BoardGraph_NoShortestPathsGreaterThanFour()
        {
            BoardGraph graph = new BoardGraph();

            List <NodeMapKey> actual = graph.NodeMap.Keys.Where(k => k.Movement > 4).ToList();

            Assert.AreEqual(actual.Count, 0);
        }
Exemplo n.º 3
0
 void Awake()
 {
     if (info == null)
     {
         BoardGraph.info = this;
     }
     else if (info != this)
     {
         Destroy(gameObject);
     }
 }
Exemplo n.º 4
0
    public void EnableAjdacentTiles()
    {
        DisableAllTiles();
        board[selectedTile.id].button.interactable = true; //enable the clicked tile

        int[] tiles = BoardGraph.GetAdjacentNodes(selectedTile.id);
        for (int i = 0; i < tiles.Length; i++)
        {
            board[tiles[i]].button.interactable = TestTile(tiles[i], selectedTile.Player);
        }
    }
Exemplo n.º 5
0
        void Start()
        {
            Client = GameManager.Instance.Client;

            if (Client.IsPlayer)
            {
                Destroy(gameObject);
                return;
            }

            Instance = this;

            GameGraph        = new BoardGraph();
            BoardSpaces      = new Dictionary <int, BoardSpace>();
            FriendlyMonsters = new List <Monster>();
            EnemyMonsters    = new List <Monster>();
            AttackCalculator = new AttackCalculator();
            MoveCalculator   = new MoveCalculator();

            AvailablePushDestinations = new List <Node>();

            BattleSmoke.gameObject.SetActive(false);

            Client.GameState = this;

            float attackResultTextRotationOffset = Client.IsHost ? 180 : 0;

            AttackResultTextPrefab.YRotationOffset = attackResultTextRotationOffset;

            _actionNumber = 1;

            if (!Client.IsHost)
            {
                _actionNumber = 3;

                var table = GameObject.Find("Table");
                table.transform.localRotation = Quaternion.Euler(table.transform.localRotation.eulerAngles.x,
                                                                 table.transform.localRotation.eulerAngles.y + 180, table.transform.localRotation.eulerAngles.z);
            }

            _subActionNumber = 1;

            for (int i = 0; i < SpacePrefabs.Count; i++)
            {
                BoardSpace spacePrefab = SpacePrefabs[i];
                if (!BoardSpaces.ContainsKey(i))
                {
                    spacePrefab.Node = GameGraph.Nodes[i];
                    BoardSpaces.Add(i, spacePrefab);
                }
            }
        }
Exemplo n.º 6
0
        public void BoardGraph_EachNodeHasExpectedNumberOfNodesAtVariousDistances()
        {
            const int innerOneExpected    = 4;
            const int innerTwoExpected    = 11;
            const int innerThreeExpected  = 9;
            const int innerFourExpected   = 0;
            const int outerOneExpected    = 3;
            const int outerTwoExpected    = 5;
            const int outerThreeExpected  = 11;
            const int outerFourExpected   = 5;
            const int centerOneExpected   = 12;
            const int centerTwoExpected   = 12;
            const int centerThreeExpected = 0;
            const int centerFourExpected  = 0;


            BoardGraph graph = new BoardGraph();

            List <NodeMapKey> centerOneActual   = graph.NodeMap.Keys.Where(k => k.NodeId == 0 && k.Movement == 1).ToList();
            List <NodeMapKey> centerTwoActual   = graph.NodeMap.Keys.Where(k => k.NodeId == 0 && k.Movement == 2).ToList();
            List <NodeMapKey> centerThreeActual = graph.NodeMap.Keys.Where(k => k.NodeId == 0 && k.Movement == 3).ToList();
            List <NodeMapKey> centerFourActual  = graph.NodeMap.Keys.Where(k => k.NodeId == 0 && k.Movement == 4).ToList();

            for (int i = 13; i < 25; i++)
            {
                List <NodeMapKey> innerOneActual   = graph.NodeMap.Keys.Where(k => k.NodeId == i - 12 && k.Movement == 1).ToList();
                List <NodeMapKey> innerTwoActual   = graph.NodeMap.Keys.Where(k => k.NodeId == i - 12 && k.Movement == 2).ToList();
                List <NodeMapKey> innerThreeActual = graph.NodeMap.Keys.Where(k => k.NodeId == i - 12 && k.Movement == 3).ToList();
                List <NodeMapKey> innerFourActual  = graph.NodeMap.Keys.Where(k => k.NodeId == i - 12 && k.Movement == 4).ToList();


                List <NodeMapKey> outerOneActual   = graph.NodeMap.Keys.Where(k => k.NodeId == i && k.Movement == 1).ToList();
                List <NodeMapKey> outerTwoActual   = graph.NodeMap.Keys.Where(k => k.NodeId == i && k.Movement == 2).ToList();
                List <NodeMapKey> outerThreeActual = graph.NodeMap.Keys.Where(k => k.NodeId == i && k.Movement == 3).ToList();
                List <NodeMapKey> outerFourActual  = graph.NodeMap.Keys.Where(k => k.NodeId == i && k.Movement == 4).ToList();

                Assert.AreEqual(innerOneActual.Count, innerOneExpected);
                Assert.AreEqual(innerTwoActual.Count, innerTwoExpected);
                Assert.AreEqual(innerThreeActual.Count, innerThreeExpected);
                Assert.AreEqual(innerFourActual.Count, innerFourExpected);

                Assert.AreEqual(outerOneActual.Count, outerOneExpected);
                Assert.AreEqual(outerTwoActual.Count, outerTwoExpected);
                Assert.AreEqual(outerThreeActual.Count, outerThreeExpected);
                Assert.AreEqual(outerFourActual.Count, outerFourExpected);
            }

            Assert.AreEqual(centerOneActual.Count, centerOneExpected);
            Assert.AreEqual(centerTwoActual.Count, centerTwoExpected);
            Assert.AreEqual(centerThreeActual.Count, centerThreeExpected);
            Assert.AreEqual(centerFourActual.Count, centerFourExpected);
        }
Exemplo n.º 7
0
        public void BoardGraph_NodeSurroundedByOccupiedNodesHasNoMovements()
        {
            List <Node> excludedNodes = new List <Node> {
                new Node(13), new Node(0), new Node(2), new Node(12)
            };

            BoardGraph graph = new BoardGraph(excludedNodes);

            List <NodeMapKey> actualKeys = graph.NodeMap.Keys.Where(k => k.NodeId == 1).ToList();

            Assert.AreEqual(actualKeys.Count, 1);
            Assert.AreEqual(actualKeys[0].NodeId, 1);
        }
Exemplo n.º 8
0
    bool hasPosibility()
    {
        int vertex = getActualVertex();

        for (int i = 0; i < 26; i++)
        {
            int weight = BoardGraph.getWeight(vertex, i);
            if (weight != -1 && !isVisited(i))
            {
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 9
0
    public List <string> find(int value)
    {
        int           vertex = getActualVertex();
        List <string> path   = new List <string>();

        for (int i = 0; i < 26; i++)
        {
            int weight = BoardGraph.getWeight(vertex, i);
            if (weight != -1 && weight == value && !isVisited(i))
            {
                path.Add(i.ToString());
            }
        }
        return(path);
    }
Exemplo n.º 10
0
        public void BoardGraph_NodeMapExcludesSpecifiedNodesInCalculation()
        {
            List <Node> excludedNodes = new List <Node> {
                new Node(0)
            };
            BoardGraph graph = new BoardGraph(excludedNodes);

            List <NodePath> actual = graph.NodeMap[new NodeMapKey(14, 3)];

            //17,23,12,4
            Assert.AreEqual(actual.Count, 4);
            Assert.IsTrue(actual.Select(n => n.DestinationNode.Id).Contains(17));
            Assert.IsTrue(actual.Select(n => n.DestinationNode.Id).Contains(23));
            Assert.IsTrue(actual.Select(n => n.DestinationNode.Id).Contains(12));
            Assert.IsTrue(actual.Select(n => n.DestinationNode.Id).Contains(4));
        }
Exemplo n.º 11
0
        void Start()
        {
            DontDestroyOnLoad(gameObject);

            ActionNumber    = 1;
            SubActionNumber = 1;

            GameGraph        = new BoardGraph();
            HostMonsters     = new List <Monster>();
            GuestMonsters    = new List <Monster>();
            AttackCalculator = new AttackCalculator();
            MoveCalculator   = new MoveCalculator();

            AvailablePushDestinations = new List <Node>();

            GameManager gameManager = GameManager.Instance;

            if (gameManager == null || gameManager.Server == null)
            {
                throw new InvalidOperationException("Server must exist to begin game");
            }

            _hostServer = gameManager.Server;

            if (_hostServer == null || !_hostServer.IsServerStarted)
            {
                throw new InvalidOperationException("Server must be running to begin game");
            }

            if (SceneManager.GetSceneByName("startup").isLoaded)
            {
                SceneManager.UnloadSceneAsync("startup");
            }

            AssignMonstersToPlayers();

            GameStartMessage gameStartMessage = new GameStartMessage
            {
                HostMonsters    = JsonConvert.SerializeObject(HostMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id)),
                GuestMonsters   = JsonConvert.SerializeObject(GuestMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id)),
                ActionNumber    = 1,
                SubActionNumber = 1
            };

            _hostServer.SendToAll(gameStartMessage.MessageTypeId, gameStartMessage);
        }
Exemplo n.º 12
0
        public void BoardGraph_ShortestPathsFromCenterAreAccurate()
        {
            BoardGraph graph = new BoardGraph();

            Assert.IsNotNull(graph.NodeMap);

            for (int i = 13; i < 25; i++)
            {
                List <NodePath> actualNodePath = graph.NodeMap[new NodeMapKey(0, 1)];
                Assert.IsTrue(actualNodePath.Select(x => x.DestinationNode).Contains(graph.Nodes[i - 12]));
                Assert.AreEqual(1, actualNodePath.Single(x => x.DestinationNode.Id == i - 12).PathToDestination.Count());
                Assert.AreEqual(graph.Nodes[i - 12].Id, actualNodePath.Single(x => x.DestinationNode.Id == i - 12).PathToDestination[0].Id);


                actualNodePath = graph.NodeMap[new NodeMapKey(0, 2)];
                Assert.IsTrue(actualNodePath.Select(x => x.DestinationNode).Contains(graph.Nodes[i]));
                Assert.AreEqual(2, actualNodePath.Single(x => x.DestinationNode.Id == i).PathToDestination.Count());
                Assert.AreEqual(graph.Nodes[i].Id, actualNodePath.Single(x => x.DestinationNode.Id == i).PathToDestination[1].Id);
                Assert.AreEqual(graph.Nodes[i - 12].Id, actualNodePath.Single(x => x.DestinationNode.Id == i).PathToDestination[0].Id);
            }
        }
Exemplo n.º 13
0
 void dijkstra(int startNode)
 {
     distance[startNode] = 0;
     for (int i = 0; i < 26; i++)
     {
         int lower = getLowerNotVisited();
         visited[lower] = true;
         for (int j = 0; j < 26; j++)
         {
             int weight = BoardGraph.getWeight(lower, j);
             if (weight == -1)
             {
                 continue;
             }
             int newDistance = distance[lower] + weight;
             if (newDistance < distance[j])
             {
                 distance[j] = newDistance;
             }
         }
     }
 }
Exemplo n.º 14
0
        void Start()
        {
            Client = GameManager.Instance.Client;

            if (!Client.IsPlayer)
            {
                Destroy(gameObject);
                return;
            }


            Instance = this;

            GameGraph        = new BoardGraph();
            BoardSpaces      = new Dictionary <int, BoardSpace>();
            FriendlyMonsters = new List <Monster>();
            EnemyMonsters    = new List <Monster>();
            AttackCalculator = new AttackCalculator();
            MoveCalculator   = new MoveCalculator();

            AvailablePushDestinations = new List <Node>();

            BattleSmoke.gameObject.SetActive(false);

            Client.GameState = this;

            float attackResultTextRotationOffset = Client.IsHost ? 180 : 0;

            AttackResultTextPrefab.YRotationOffset = attackResultTextRotationOffset;

            _actionNumber = 1;

            if (!Client.IsHost)
            {
                _actionNumber = 3;

                var table = GameObject.Find("Table");
                table.transform.localRotation = Quaternion.Euler(table.transform.localRotation.eulerAngles.x,
                                                                 table.transform.localRotation.eulerAngles.y + 180, table.transform.localRotation.eulerAngles.z);
            }

            _subActionNumber = 1;

            for (int i = 0; i < SpacePrefabs.Count; i++)
            {
                BoardSpace spacePrefab = SpacePrefabs[i];
                if (!BoardSpaces.ContainsKey(i))
                {
                    spacePrefab.Node = GameGraph.Nodes[i];
                    BoardSpaces.Add(i, spacePrefab);
                }
            }

            List <Monster> friendlyMonsters = new List <Monster>();
            List <Monster> enemyMonsters    = new List <Monster>();

            foreach (Monster monster in MonsterPrefabs)
            {
                if (GameManager.Instance.FriendlyMonsterInitialNodeIds.ContainsKey(monster.MonsterTypeId))
                {
                    monster.CurrentNode = GameGraph.Nodes[GameManager.Instance.FriendlyMonsterInitialNodeIds[monster.MonsterTypeId]];
                    friendlyMonsters.Add(monster);
                }
                else
                {
                    monster.CurrentNode = GameGraph.Nodes[GameManager.Instance.EnemyMonsterInitialNodeIds[monster.MonsterTypeId]];
                    enemyMonsters.Add(monster);
                }
            }

            DisplayMonsters(friendlyMonsters, enemyMonsters);

            Client.SendStateAck(GetAdjustedActionNumber(), _subActionNumber);

            if (GameManager.Instance.Difficulty == 1)
            {
                GameObject.Find("selectionPreview").SetActive(false);
            }
        }