Exemplo n.º 1
0
 public override int Move(PongData data)
 {
     if (data.playerPos > data.ballPosX)
     {
         return(-1);
     }
     else if (data.playerPos < data.ballPosX)
     {
         return(1);
     }
     else
     {
         return(0);
     }
 }
Exemplo n.º 2
0
    private void MovePlayers()
    {
        // PLAYER ONE - DOWN
        PongData d1 = new PongData()
        {
            ballPosX  = ballTransform.position.x,
            ballPosY  = ballTransform.position.y,
            ballDirX  = ballRigidbody.velocity.x,
            ballDirY  = ballRigidbody.velocity.y,
            ballSpeed = ball.getSpeed(),
            playerPos = playerTransforms[0].position.x,
            enemyPos  = playerTransforms[1].position.x,
        };
        // move
        int     command1 = players[0].Move(d1);
        Vector2 pos1     = playerTransforms[0].position;

        pos1.x = Mathf.Clamp(pos1.x + command1 * moveSpeed * Time.deltaTime, -posLimit, posLimit);
        playerTransforms[0].position = pos1;

        // PLAYER TWO - UP
        PongData d2 = new PongData()
        {
            ballPosX  = -ballTransform.position.x,
            ballPosY  = -ballTransform.position.y,
            ballDirX  = -ballRigidbody.velocity.x,
            ballDirY  = -ballRigidbody.velocity.y,
            ballSpeed = ball.getSpeed(),
            playerPos = -playerTransforms[1].position.x,
            enemyPos  = -playerTransforms[0].position.x,
        };
        // move
        int     command2 = players[1].Move(d2);
        Vector2 pos2     = playerTransforms[1].position;

        pos2.x = Mathf.Clamp(pos2.x - command2 * moveSpeed * Time.deltaTime, -posLimit, posLimit);
        playerTransforms[1].position = pos2;


        // TEACH IF NEEDED
        if (LevelData.instance.type == LEVEL_TYPE.SOLO)
        {
            d1.playerPos = playerTransforms[0].position.x;
            //d1.Normalize();
            roundData.Add(d1);
            info.text = "ROUND: " + roundData.Count + "\nLEVEL: " + trainData.Count;
        }
    }
Exemplo n.º 3
0
    public double Predict(PongData data)
    {
        if (model == null)
        {
            return(0);
        }

        double[] observations = new double[] {
            data.ballPosX,
            data.ballPosY,
            data.ballDirX,
            data.ballDirY
        };

        return(model.Predict(observations));;
    }
Exemplo n.º 4
0
    public override int Move(PongData data)
    {
        double dir = sml.Predict(data) - data.playerPos;

        if (Mathf.Abs((float)dir) < limit)
        {
            return(0);
        }
        if (dir > 0)
        {
            return(1);
        }
        if (dir < 0)
        {
            return(-1);
        }
        return(0);
    }
Exemplo n.º 5
0
    public override int Move(PongData data)
    {
        int right = Input.GetKey(rightInput) ? 1 : 0;
        int left  = Input.GetKey(leftInput) ? 1 : 0;
        int dir   = right - left;

        if (Input.GetMouseButton(0))
        {
            Vector2 mouse = Input.mousePosition;
            if (mouse.y < Screen.height / 2)
            {
                right = mouse.x > Screen.width / 2 ? 1 : 0;
                left  = mouse.x < Screen.width / 2 ? 1 : 0;
                dir   = right - left;
            }
        }

        return(dir);
    }
Exemplo n.º 6
0
    public int Move(PongData data)
    {
        Player player = null;

        switch (playerController)
        {
        case PLAYER_TYPE.MACHINE:
            player = machinePlayer;
            break;

        case PLAYER_TYPE.PLAYER:
            player = keyboardPlayer;
            break;

        case PLAYER_TYPE.FOLLOWER:
            player = followPlayer;
            break;
        }

        return(player.Move(data));
    }
Exemplo n.º 7
0
 public abstract int Move(PongData data);