Example #1
0
    // Constructor method that simplifies a world into a state
    public SimplifiedWorld(World world, int playerNum)
    {
        World.Player player;
        World.Player enemy;

        // Set the player and enemy
        if (playerNum == 1)
        {
            player = world.Player1;
            enemy  = world.Player2;
        }
        else
        {
            player = world.Player2;
            enemy  = world.Player1;
        }

        // Set the player and enemy weapons and ammo amounts
        if (player.Ammo == 0)
        {
            Weapon = WeaponType.None;
        }
        else
        {
            Weapon = player.Weapon;
        }

        if (enemy.Ammo == 0)
        {
            EnemyWeapon = WeaponType.None;
        }
        else
        {
            EnemyWeapon = enemy.Weapon;
        }

        AmmoAmount      = player.Ammo;
        EnemyAmmoAmount = enemy.Ammo;

        // Convert these distances into closeness types
        XDistanceToEnemy = HowXClose(world);
        YDistanceToEnemy = HowYClose(world, playerNum);


        // Set the player and enemy health
        health      = player.Health;
        enemyHealth = enemy.Health;
    }
Example #2
0
    // Returns all possible states
    static public List <SimplifiedWorld> AllPossible()
    {
        // Create empty list
        List <SimplifiedWorld> stateList = new List <SimplifiedWorld>();

        // Iterate through each property
        WeaponType[] weaponArray = new WeaponType[] {
            WeaponType.None,
            WeaponType.Bombs,
            WeaponType.Rockets,
            WeaponType.Minions,
            WeaponType.Lightning
        };

        int[] ammoArray = new int[] { -1, 0, 1, 2, 3 };

        XCloseness[] xClosenessArray = new XCloseness[] {
            XCloseness.Near,
            XCloseness.Medium,
            XCloseness.Far,
            XCloseness.WallBetween
        };

        YCloseness[] yClosenessArray = new YCloseness[] {
            YCloseness.PosNear,
            YCloseness.PosMedium,
            YCloseness.PosFar,
            YCloseness.NegNear,
            YCloseness.NegMedium,
            YCloseness.NegFar,
            YCloseness.WallBetween
        };

        // weapon
        foreach (WeaponType tempWeapon in weaponArray)
        {
            // ammoAmount
            foreach (int tempAmmoAmount in ammoArray)
            {
                // enemyWeapon
                foreach (WeaponType tempEnemyWeapon in weaponArray)
                {
                    // enemyAmmoAmount
                    foreach (int tempEnemyAmmoAmount in ammoArray)
                    {
                        // xDistanceToEnemy
                        foreach (XCloseness tempXDistanceToEnemy in xClosenessArray)
                        {
                            // yDistanceToEnemy
                            foreach (YCloseness tempYDistanceToEnemy in yClosenessArray)
                            {
                                // Create new state class with the above properties
                                SimplifiedWorld newState = new SimplifiedWorld();
                                newState.Weapon           = tempWeapon;
                                newState.AmmoAmount       = tempAmmoAmount;
                                newState.EnemyWeapon      = tempEnemyWeapon;
                                newState.EnemyAmmoAmount  = tempEnemyAmmoAmount;
                                newState.XDistanceToEnemy = tempXDistanceToEnemy;
                                newState.YDistanceToEnemy = tempYDistanceToEnemy;

                                // Add newState to stateList
                                stateList.Add(newState);
                            }
                        }
                    }
                }
            }
        }

        return(stateList);
    }