/// <inheritdoc />
        public ISymbolicNumericType <T> Range(SymbolicConstant <T> min, bool minIncluded, SymbolicConstant <T> max, bool maxIncluded)
        {
            if (min.ConstantGreaterThan(max))
            {
                throw new ArgumentException("min should be lower or equal to max");
            }
            // Should not be the min for any other Chunk
            if (min.Symbolic)
            {
                Chunks.ForEach(chunk =>
                {
                    if (chunk.Min.Equals(min))
                    {
                        throw new ArgumentException("min already declared");
                    }
                });
            }

            // Should not be the min for any other Chunk
            if (max.Symbolic)
            {
                Chunks.ForEach(chunk =>
                {
                    if (chunk.Max.Equals(max))
                    {
                        throw new ArgumentException("max already declared");
                    }
                });
            }

            Chunks.Add(new SymbolicChunk <T>(min, max, minIncluded, maxIncluded));
            return(this);
        }
Esempio n. 2
0
 public void Deconstruct(out SymbolicConstant <T> min, out bool minIncluded, out SymbolicConstant <T> max, out bool maxIncluded)
 {
     min         = Min;
     minIncluded = MinIncluded;
     max         = Max;
     maxIncluded = MaxIncluded;
 }
Esempio n. 3
0
 /// <summary>
 ///     Instantiates a chunk
 /// </summary>
 /// <param name="min">The min value (included) of the chunk.</param>
 /// <param name="max">The max value (included) of the chunk.</param>
 /// <param name="minIncluded">
 ///     The minimum value included in this chunk. This is <paramref name="min" /> when <paramref name="min" /> is included,
 ///     the smallest value over <paramref name="min" /> otherwise.
 /// </param>
 /// <param name="maxIncluded">
 ///     The maximum value included in this chunk. This is <paramref name="max" /> when <paramref name="max" /> is included,
 ///     the smallest value below <paramref name="max" /> otherwise.
 /// </param>
 public SymbolicChunk(SymbolicConstant <T> min, SymbolicConstant <T> max, bool minIncluded, bool maxIncluded)
 {
     Min         = min;
     Max         = max;
     MinIncluded = minIncluded;
     MaxIncluded = maxIncluded;
 }
Esempio n. 4
0
        public SymbolicConstant GetNextMove(InputProgram facts)
        {
            SymbolicConstant move             = new SymbolicConstant();
            string           encodingResource = @".\encodings\pacman.asp";
            //string encodingResource2 = @"encodings\min_distances_5.asp";
            //Debug.Log("DLV Started: " + numberOfSteps++);
            Handler      handler  = new DesktopHandler(new DLVDesktopService(@".\lib\dlv.exe"));
            InputProgram encoding = new ASPInputProgram();

            encoding.AddFilesPath(encodingResource);
            //InputProgram encoding2 = new ASPInputProgram();
            //encoding.AddFilesPath(encodingResource2);
            handler.AddProgram(encoding);
            //handler.AddProgram(encoding2);
            handler.AddProgram(facts);
            handler.AddOption(new OptionDescriptor("-filter=next"));
            Output o = handler.StartSync();
            //EmbaspCall++;



            AnswerSets answers = (AnswerSets)o;

            System.Random r      = new System.Random();
            int           answer = r.Next(answers.Answersets.Count);
            AnswerSet     a      = answers.Answersets[answer];

            foreach (object obj in a.Atoms)
            {
                //Debug.Log(obj.ToString());
                if (obj is Next)
                {
                    Next nextAction = (Next)obj;

                    move = nextAction.getAction();
                    return(move);
                    //Debug.Log("Next Action: " + move);
                }
            }
            return(move);
        }
Esempio n. 5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        switch (GameManager.gameState)
        {
        case GameManager.GameState.Game:

            if (keyboard)
            {
                ReadInputAndMove(new SymbolicConstant());
            }
            else
            {
                //StartCoroutine(GetText());
                SymbolicConstant newMove    = embasp.PreviousMove;
                Vector3          currentPos = new Vector3((int)(embasp.Pacman.transform.position.x + 0.499f), (int)(embasp.Pacman.transform.position.y + 0.499f));
                //Debug.Log(currentPos + " " + previousPos);
                if (Math.Abs(currentPos.x - embasp.PreviousPos.x) + Math.Abs(currentPos.y - embasp.PreviousPos.y) >= 1)
                {
                    //Debug.Log("Current Pos: " + currentPos);
                    embasp.PreviousPos = currentPos;
                    newMove            = embasp.ASPMove();
                }
                ReadInputAndMove(newMove);
            }
            Animate();
            break;

        case GameManager.GameState.Dead:
            if (!_deadPlaying)
            {
                EmbASPManager.Instance.GenerateCharacters();
            }
            StartCoroutine("PlayDeadAnimation");
            break;
        }
    }
Esempio n. 6
0
        public SymbolicConstant ASPMove()
        {
            //PRENDE LA POSIZIONE DEL PACMAN
            Vector3 currentPos  = new Vector3(Pacman.transform.position.x + 0.499f, Pacman.transform.position.y + 0.499f);
            var     currentTile = Tiles[manager.Index((int)currentPos.x, (int)currentPos.y)];

            //Debug.Log("PACMAN POS --> X:" + currentPos.x + " Y: " + currentPos.y + "\n\nTile --> X: " + currentTile.x + " Y: " + currentTile.y);

            //FIND ADJACENT TILES TO THE CURRENT ONE
            TileManager.Tile down  = currentTile.down;
            TileManager.Tile up    = currentTile.up;
            TileManager.Tile left  = currentTile.left;
            TileManager.Tile right = currentTile.right;

            InputProgram  facts       = new ASPInputProgram();
            StringBuilder disjunction = new StringBuilder();

            Pacman myPacman = new Pacman((int)currentPos.x, (int)currentPos.y);

            if (down != null)
            {
                if (disjunction.Length > 0)
                {
                    disjunction.Append("|");
                }
                disjunction.Append("next(down)");
            }

            if (left != null)
            {
                if (disjunction.Length > 0)
                {
                    disjunction.Append("|");
                }
                disjunction.Append("next(left)");
            }

            if (up != null)
            {
                if (disjunction.Length > 0)
                {
                    disjunction.Append("|");
                }
                disjunction.Append("next(up)");
            }

            if (right != null)
            {
                if (disjunction.Length > 0)
                {
                    disjunction.Append("|");
                }
                disjunction.Append("next(right)");
            }
            disjunction.Append(".");
            facts.AddProgram(disjunction.ToString());
            if (PreviousMove != null)
            {
                facts.AddProgram("previous_action(" + PreviousMove.Value + ").");
            }
            facts.AddObjectInput(myPacman);


            GameObject[] pacdots = GameObject.FindGameObjectsWithTag("pacdot");
            //Debug.Log("SIZE DOT: " + pacdots.Length);

            int count = 0;

            foreach (TileManager.Tile t in Tiles)
            {
                if (!t.occupied)
                {
                    count++;
                }
            }
            //Debug.Log("SIZE TILE: " + count);
            //GameObject[] energizer; // sono pacdot anche loro

            //energizer = GameObject.FindGameObjectsWithTag("energizer");

            //CHECK THE CONTENT OF A TILE
            //Debug.Log("PacDot[0].pos = (" + pacdots[0].transform.position.x + "," + pacdots[0].transform.position.y + ")");

            //for (int i = 0; i < 28; i++)
            //  for (int j = 0; j < 32; j++)
            //    foreach (Distance d in distances[i,j])
            //      facts.AddObjectInput(d);


            for (int i = -1; i <= 1; i++)
            {
                if (myPacman.getX() + i > 0 && myPacman.getX() + i < 28)
                {
                    if (GameManager.scared)
                    {
                        foreach (Distance d in distances_10[myPacman.getX() + i, myPacman.getY()])
                        {
                            facts.AddObjectInput(d);
                        }
                    }
                    else
                    {
                        foreach (Distance d in distances_5[myPacman.getX() + i, myPacman.getY()])
                        {
                            facts.AddObjectInput(d);
                        }
                    }
                }
                if (myPacman.getY() + i > 0 && myPacman.getY() + i < 32)
                {
                    if (GameManager.scared)
                    {
                        foreach (Distance d in distances_10[myPacman.getX(), myPacman.getY() + i])
                        {
                            facts.AddObjectInput(d);
                        }
                    }
                    else
                    {
                        foreach (Distance d in distances_5[myPacman.getX(), myPacman.getY() + i])
                        {
                            facts.AddObjectInput(d);
                        }
                    }
                }
            }

            if (GameManager.scared)
            {
                facts.AddProgram("powerup.");
            }


            foreach (GameObject p in pacdots)
            {
                facts.AddProgram("pellet(" + (int)p.transform.position.x + "," + (int)p.transform.position.y + ").");
            }

            facts.AddProgram("ghost(" + (int)blinky.transform.position.x + "," + (int)blinky.transform.position.y + ",blinky).");
            facts.AddProgram("ghost(" + (int)inky.transform.position.x + "," + (int)inky.transform.position.y + ",inky).");
            facts.AddProgram("ghost(" + (int)clyde.transform.position.x + "," + (int)clyde.transform.position.y + ",clyde).");
            facts.AddProgram("ghost(" + (int)pinky.transform.position.x + "," + (int)pinky.transform.position.y + ",pinky).");


            TileManager.Tile pacmanTile = new TileManager.Tile((int)Pacman.transform.position.x, (int)Pacman.transform.position.y);

            TileManager.Tile first_min = new TileManager.Tile((int)pacdots[0].transform.position.x, (int)pacdots[0].transform.position.y);
            var minDistance            = 10E6;// manager.distance(pacmanTile, first_min);



            foreach (GameObject p in pacdots)
            {
                TileManager.Tile pacdotsTile = new TileManager.Tile((int)p.transform.position.x, (int)p.transform.position.y);
                var myDistance = manager.distance(pacmanTile, pacdotsTile);
                if (myDistance < minDistance)
                {
                    minDistance = myDistance;
                    first_min   = pacdotsTile;
                }
            }

            facts.AddProgram("closestPellet(" + first_min.x + "," + first_min.y + ").");
            facts.AddProgram("distanceClosestPellet(" + (int)minDistance + ").");


            foreach (TileManager.Tile p in Tiles)
            {
                if (!p.occupied)
                {
                    facts.AddProgram("tile(" + p.x + "," + p.y + ").");
                }
            }

            SymbolicConstant move = GetNextMove(facts);

            PreviousMove = move;
            //Debug.Log("CurrentMove: " + move);
            return(move);
        }
 /// <inheritdoc />
 public ISymbolicNumericType <T> Value(SymbolicConstant <T> value) => Range(value, value);
 /// <inheritdoc />
 public ISymbolicNumericType <T> Below(SymbolicConstant <T> max) => Range(MinValue, true, max, false);
 /// <inheritdoc />
 public ISymbolicNumericType <T> BelowOrEqual(SymbolicConstant <T> max) => Range(MinValue, max);
 /// <inheritdoc />
 public ISymbolicNumericType <T> Above(SymbolicConstant <T> min) => Range(min, false, MaxValue, true);
 /// <inheritdoc />
 public ISymbolicNumericType <T> AboveOrEqual(SymbolicConstant <T> min) => Range(min, MaxValue);
 /// <inheritdoc />
 public ISymbolicNumericType <T> Range(SymbolicConstant <T> min, SymbolicConstant <T> max) => Range(min, true, max, true);
Esempio n. 13
0
 public void SetNextMove(SymbolicConstant value)
 {
     nextMove = value;
 }
Esempio n. 14
0
 public MyCallback(SymbolicConstant nextMove)
 {
     this.nextMove = nextMove;
 }
Esempio n. 15
0
 public void setAction(SymbolicConstant value)
 {
     action = value;
 }
Esempio n. 16
0
    void ReadInputAndMove(SymbolicConstant nextStep)
    {
        // move closer to destination
        Vector2 p = Vector2.MoveTowards(transform.position, _dest, speed);

        GetComponent <Rigidbody2D>().MovePosition(p);

        // get the next direction from keyboard
        //Debug.Log("NEXT: <" + nextStep + ">");
        if (!keyboard)
        {
            if (nextStep.Value.Equals("right"))
            {
                _nextDir = Vector2.right;
            }
            if (nextStep.Value.Equals("left"))
            {
                _nextDir = -Vector2.right;
            }
            if (nextStep.Value.Equals("up"))
            {
                _nextDir = Vector2.up;
            }
            if (nextStep.Value.Equals("down"))
            {
                _nextDir = -Vector2.up;
            }
        }
        else
        {
            // get the next direction from keyboard
            if (Input.GetAxis("Horizontal") > 0)
            {
                _nextDir = Vector2.right;
            }
            if (Input.GetAxis("Horizontal") < 0)
            {
                _nextDir = -Vector2.right;
            }
            if (Input.GetAxis("Vertical") > 0)
            {
                _nextDir = Vector2.up;
            }
            if (Input.GetAxis("Vertical") < 0)
            {
                _nextDir = -Vector2.up;
            }
        }

        // if pacman is in the center of a tile
        if (Vector2.Distance(_dest, transform.position) < 0.00001f)
        {
            if (Valid(_nextDir))
            {
                _dest = (Vector2)transform.position + _nextDir;
                _dir  = _nextDir;
            }
            else // if next direction is not valid
            {
                if (Valid(_dir)) // and the prev. direction is valid
                {
                    _dest = (Vector2)transform.position + _dir; // continue on that direction
                }
                // otherwise, do nothing
            }
        }
        if (Input.GetKeyDown(KeyCode.K))
        {
            keyboard = !keyboard;
        }

        //if (watch.Elapsed.Minutes == 1 && watch.Elapsed.Seconds == 0 && watch.Elapsed.Milliseconds == 0)
        //Debug.Log("EmbASP CALL: " + EmbASPManager.Instance.EmbaspCall + "\nTime: " + watch.Elapsed.Minutes + ":" + watch.Elapsed.Seconds + ":" + watch.Elapsed.Milliseconds);
    }