示例#1
0
 private void GenerateExtraEdges(float extraEdgeProbability)
 {
     if (Math.Abs(extraEdgeProbability) < 0.000001)
     {
         return;
     }
     foreach (ShipmentNode node in Nodes)
     {
         foreach (ShipmentNode otherNode in Nodes)
         {
             if (node.Id == otherNode.Id)
             {
                 continue;
             }
             if (GetEdge(node.Id, otherNode.Id) != null)
             {
                 continue;
             }
             bool b  = GetEdgesByIdNode(node.Id).Count < 2;
             bool b1 = GetEdgesByIdNode(otherNode.Id).Count < 2;
             if (Random.Range(0, 1) < extraEdgeProbability && b && b1 /* && Edges.Count < (Nodes.Count/2)  * 3 - 4 */)
             {
                 ShipmentEdge shipmentEdge = new ShipmentEdge
                 {
                     IdNodeA = node.Id,
                     IdNodeB = otherNode.Id,
                 };
                 Edges.Add(shipmentEdge);
             }
         }
     }
 }
示例#2
0
        public void OnClickOk()
        {
            Player.gameObject.SetActive(true);
            MapGenerator.Ruler.gameObject.SetActive(false);
            MapGenerator.Ruler.UnFix();
            EnableComponents(false);
            _edgesAnswers.Clear();

            OkButton.enabled = false;

            PlaySoundClick();
            EnableGameButtons(false);


            for (int i = 0; i < AnswerRowGameObjects.Length; i++)
            {
                GameObject answerRowGameObject         = AnswerRowGameObjects[i];
                List <ShipmentsAnswerCell> answerCells = answerRowGameObject.GetComponentsInChildren <ShipmentsAnswerCell>().ToList();
                if (answerCells[0].Value == -1)
                {
                    break;
                }
                ShipmentEdge shipmentEdge = new ShipmentEdge
                {
                    IdNodeA = answerCells[0].Value,
                    IdNodeB = answerCells[1].Value,
                    Length  = answerCells[2].Value
                };
                _edgesAnswers.Add(shipmentEdge);
            }

            ContinueCorrection(_edgesAnswers, 0);
        }
示例#3
0
        private void CheckEdgeAnswer(ShipmentEdge realEdge, List <ShipmentEdge> edgeAnswers, int index)
        {
            if (index > 0)
            {
                Invoke("PlayBoatSond", 0.2f);
            }
            else
            {
                PlayBoatSond();
            }
            // no hay arista
            if (realEdge == null)
            {
                AnswerEdgeNotExists(
                    MapGenerator.Places.Find(e => e.Id == edgeAnswers[index].IdNodeB).transform.position, 2, edgeAnswers);
                return;
            }
            ;

            var      answerEdge = edgeAnswers[index];
            MapPlace destine    = MapGenerator.Places.Find(e => e.Id == answerEdge.IdNodeB);

            int answerValue = answerEdge.Length / (Model.Scale);
            int rest        = answerEdge.Length % Model.Scale;

            // caso correcto
            if (answerValue == realEdge.Length && rest == 0)
            {
                Player.transform.DOMove(destine.transform.position, GetDuration(realEdge.Length))
                .OnComplete(() =>
                {
                    AddGold();
                    index++;
                    indexToCorrect = index;
                    Invoke("CorrectAnswerContinueCorrection", 1);
                });
            }
            // se pasó
            else if (answerValue >= realEdge.Length)
            {
                AnswerEdgeTooLong(destine.transform.position, realEdge.Length, edgeAnswers);
            }

            // se quedó corto
            else
            {
                AnswerEdgeTooShort(destine.transform.position, realEdge.Length);
            }
        }
示例#4
0
        private void GenerateSolutionPaths(int solutionPaths, List <int> edgesBySolutionPath)
        {
            // hago - 2 xq el ultimo se lo voy a agregar al final. El 0 lo agrego si o si.
            Randomizer nodeRandomizer = Randomizer.New(Nodes.Count - 2, 1, false);

            for (int i = solutionPaths - 1; i >= 0; i--)
            {
                nodeRandomizer.Restart();
                int           pathLength    = edgesBySolutionPath[i];
                ShipmentsPath shipmentsPath = new ShipmentsPath
                {
                    // Agrego el primero
                    // la cantidad de nodos es la de aristas + 1
                    NodesList = new List <ShipmentNode>(pathLength + 1)
                    {
                        Nodes[0]
                    }
                };
                // es -3 xq el 0 y el ultimo ya estan fijos
                for (int j = 1; j <= shipmentsPath.NodesList.Capacity - 2; j++)
                {
                    ShipmentNode shipmentNode = Nodes[nodeRandomizer.Next()];

                    while (shipmentsPath.NodesList.Exists(e => e.Id == shipmentNode.Id) || GetEdgesByIdNode(shipmentNode.Id).Count > 2)
                    {
                        shipmentNode = Nodes[nodeRandomizer.Next()];
                    }
                    shipmentsPath.NodesList.Add(shipmentNode);

                    if (!ExistsEdge(shipmentsPath.NodesList[j - 1].Id, shipmentsPath.NodesList[j].Id))
                    {
                        ShipmentEdge edge = new ShipmentEdge();
                        edge.IdNodeA = shipmentsPath.NodesList[j - 1].Id;
                        edge.IdNodeB = shipmentsPath.NodesList[j].Id;
                        Edges.Add(edge);
                    }
                }
                // Agrego el ultimo
                shipmentsPath.NodesList.Add(Nodes[Nodes.Count - 1]);
                ShipmentEdge lastEdge = new ShipmentEdge();
                lastEdge.IdNodeA = shipmentsPath.NodesList[shipmentsPath.NodesList.Count - 2].Id;
                lastEdge.IdNodeB = shipmentsPath.NodesList[shipmentsPath.NodesList.Count - 1].Id;
                Edges.Add(lastEdge);

                _solutionPaths.Add(shipmentsPath);
            }
        }
示例#5
0
 private void ContinueCorrection(List <ShipmentEdge> edgeAnswers, int index)
 {
     if (index == edgeAnswers.Count)
     {
         FinalCheckAnswer();
     }
     else
     {
         ShipmentEdge edge =
             Model.Edges.Find(
                 e =>
         {
             var shipmentEdge = edgeAnswers[index];
             return((e.IdNodeA == shipmentEdge.IdNodeA && e.IdNodeB == shipmentEdge.IdNodeB) ||
                    (e.IdNodeB == shipmentEdge.IdNodeA && e.IdNodeA == shipmentEdge.IdNodeB));
         });
         CheckEdgeAnswer(edge, edgeAnswers, index);
     }
 }
示例#6
0
        public bool IsCorrectAnswer(List <ShipmentEdge> edgeAnswers)
        {
            for (int i = 0; i < edgeAnswers.Count; i++)
            {
                edgeAnswers[i].Length = edgeAnswers[i].Length / Scale;
                ShipmentEdge edge = Edges.Find(e => e.Equals(edgeAnswers[i]));
                if (edge == null)
                {
                    return(false);
                }
            }
            bool isCorrectAnswer = edgeAnswers[edgeAnswers.Count - 1].IdNodeB == Nodes.Find(e => e.Type == ShipmentNodeType.Finish).Id;

            if (lastCorrect)
            {
                _currentLevel++;
            }
            lastCorrect = isCorrectAnswer;
            LogAnswer(isCorrectAnswer);
            return(isCorrectAnswer);
        }
示例#7
0
 public bool Equals(ShipmentEdge otherEdge)
 {
     return(Length == otherEdge.Length && (IdNodeA == otherEdge.IdNodeA && IdNodeB == otherEdge.IdNodeB) || (IdNodeB == otherEdge.IdNodeA && IdNodeA == otherEdge.IdNodeB));
 }