0

I am working on an AI project and am trying to build a Video Game Selector.

The user will input what genre, mode, rating and platform of a game they would like to play. Then the program will take that input, and then using some yet to be determined logic select games within the gameList array that match that criteria. Then, it would randomly select a game from the gameList array matching the criteria and output the randomly selected game as a suggestion for the user to play.

I'm having an issue trying to come up with the best way to use the user input to determine which games match that criteria.

My current approach does not utilize any special artificial learning or machine learning concepts to the problem. I'm rather new to Java, and I'm just trying to piece together how to best solve this problem.

If anyone has any ideas on a better approach then I currently have or a better and easier way to go about doing this that would be hugely helpful!

Here is the code I currently have (some of from a previous assignment so ignore the printPeas() and other stuff that isn't revenant to the arrays. The code currently isn't working unfortunately:

package Games;

import java.util.Scanner;

public class Games
{
    String _gameType;
    String _genreType;
    String _gameMode;
    String _gameRating;
    String _tType;

    public static Scanner input = new Scanner(System.in);

    public Games(String type)
    {
        _gameType = type;
        System.out.println("Suggested type of game is: " + _gameType);
    }
    public Games()
    {
        _gameType = "Sports";
        System.out.println("Suggested type of game is: " + _gameType);
    }
    public void typeInput(String tType)
    {
        _tType = tType;
        System.out.println("Type of Game selected: " + _tType);
    }
    public void genreInput(String gType)
    {
        _genreType = gType;
        System.out.println("Type of Genre selected: " + _genreType);
    }
    public void modeInput(String gMode)
    {
        _gameMode = gMode;
        System.out.println("Type of Game Mode selected: " + _gameMode);
    }
    public void ratingInput(String gRating)
    {
         _gameRating = gRating;
         System.out.println("Type of Rating selected: " + _gameRating);
    }
    public void printPeas()
    {
        String agent = "Agent = Video Game Seletor.";
        String perfmeasure = "P = If it meets the users information being input.";
        String environment = "E = All games within a certain location.";
        String actuators = "A = Library of games to select from, and the display of which game was selected.";
        String sensors = "S = Keyboard input.";
        System.out.println(agent);
        System.out.println(perfmeasure);
        System.out.println(environment);
        System.out.println(actuators);
        System.out.println(sensors);
    }
}


package Games;

import java.util.ArrayList;
import java.util.Random;

public class Game
{
    public static String _genreType;
    public static String _gameMode;
    public static String _gameRating;
    public static String _gameName;

    public void setGame(String genre, String mode, String rating)
    {
        _genreType = genre;
        _gameMode = mode;
        _gameRating = rating;
        _gameName = "";

        Random random = new Random();
        String gameList[] = {"NHL '18", "Madden '18", "Call of Duty: WW2", "GTA V", "Counter-Strike: Global Offsnsive",
            "World of Warcrat", "PUBG", "Assassin's Creed Origins", "Hearthstone", "Battlefield 4"};
        String genreList[] = {"Action", "Sports", "Racing", "MMORPG", "Strategy", "Fighting", "Fantasy"};
        String modeList[] = {"Multiplayer", "Online", "Campaign"};
        String ratingList[] = {"Everyone", "E10+", "Teen", "Mature"};
        String platformList[] = {"PC", "PS4", "Xbox"};
        for(int i=0; i<gameList.length; i++) //trying to have it pull a random game name matching type, genre, mode and rating
        {
            if(genre == genreList[i])
            {
                _genreType = genre;
            }
            if(mode == modeList[i])
            {
                _gameMode = mode;
            }
                System.out.println(gameList[random.nextInt(gameList.length)]);
        }
    }
}

package Games;

import java.util.Scanner;

public class StartSelector
{
    public static String _gameType;
    public static String _genreType;
    public static String _gameMode;
    public static String _gameRating;
    public static Scanner userInput = new Scanner(System.in);
    public static void main(String[] args)
    {
        String gameType = _gameType, genreType = _genreType, gameMode = _gameMode, gameRating = _gameRating;
        Games gameType1 = new Games();
        gameType1.printPeas();
        Games gameType2 = new Games("Action");
        gameType2.printPeas();
        Games gameSelect = new Games();
        System.out.println("Please enter the Genre Type: ");
        genreType = userInput.next();
        gameSelect.genreInput(genreType);
        System.out.println("Please enter the Game Type: ");
        gameType = userInput.next();
        gameSelect.typeInput(gameType);
        System.out.println("Please enter the Game Mode: ");
        gameMode = userInput.next();
        gameSelect.modeInput(gameMode);
        System.out.println("Please enter the Game Rating: ");
        gameRating = userInput.next();
        gameSelect.ratingInput(gameRating);
        userInput.close();
        System.out.println("You have selected a " + genreType + " " 
        + gameType + " " + gameMode + " " + gameRating 
        + " game to play.");
        gameType1.setGame("Action", "Online", "Mature", "GTA V");
    }
}
cptwonton
  • 500
  • 3
  • 16
  • 1
    "_so ignore the printPeas() and other stuff that isn't revenant_" It is your job to reduce the code to only what is needed to reproduce the issue. "_The code currently isn't working_" You need to explain _exactly_ how it is not working. Error? Exception? Wrong output? Lastly, you should be asking a specific question rather than a general "what should I do?" – takendarkk Jan 23 '18 at 19:29
  • What's your question? Where do you need help? – C-Otto Jan 23 '18 at 19:30
  • Possible duplicate of [How do I compare strings in Java?](https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Juan Carlos Mendoza Jan 23 '18 at 19:30
  • This site does accept nebulous questions asking for *"any ideas on a better approach"* etc. You could try asking on https://softwareengineering.stackexchange.com/, but even there you would need to be more precise about what your question is such that it is meaningfully answerable (and not "discussion like"). – Bohemian Jan 23 '18 at 19:44

1 Answers1

1

What you're describing sounds like a classical machine learning classifier problem. Seeing as you're doing this for an AI class, writing a classifier may be precisely what your professor wants you to do!

What you could do, in a very abstract way, is:

  • assign numerical values (and weights) for each of the genretype, gamemode, gamerating, ttype, for each game in gameList[] that you have.

  • compute a vector in 4d space for each of your games.

  • compute a vector for the user input

  • find the "nearest neighbor" game vector to your users inputted game vector, output this nearest neighbor game vector to your user as the suggested game

For example, the PUBG vector is:

  • Action (assigned value of 1)
  • Multiplayer (assigned value of 1)
  • Teen (assigned value of 3)
  • platformList (assigned value of 1+2+3)

Your vector for PUBG is then <1,1,3,6>. A user inputting that they want an Action game that is Multiplayer for Teen and on all three platforms would then give your classifier an input of (1,1,3,6). Your computed vector is then the same as that of PUBG, which you've already computed. Suggested game is then PUBG.

this is a really neat project you're doing. the example values I gave above are just an example and you will certainly want to tweak them. But the purpose of this is to illustrate how machine learning/AI classifiers work at a high level.

This sort of stuff is the bread and butter of machine learning/AI, and is already used widely in industry. Credit Card companies will detect fraud, for example, using classifiers.

You will likely not need to go thru the arduous process of training your classifier on training data, and then testing it on test data... that's a whole other thing. But you can use the classifier methodology - that is, using input vectors to compute an output label, to accomplish your goal.

Good luck!

cptwonton
  • 500
  • 3
  • 16
  • So I've been working on this project more and have the gameInfo read in from a text file and stored in an array (name, type, platform) and also have a text file being read in with userInput (type, input). I'm trying to compare the type and platform from the userInput with the games from gameInfo and return all the values that would match the (type, platform) from the userInput text file. I know using the .equals() is the way to go, but how do I have it so it returns only the values that match in both arrays so I can then randomly select one for the final output for the user? – Dankstuff420 Feb 05 '18 at 05:20
  • There are multiple ways to do this. One way that comes to mind is a two-pass filter. The general concept of a filter is that it takes an array and a boolean lambda function as input, and spits out a result array that contains all the array elements from the passed in array that satisfy the boolean lambda function (in your case, the first filter has a lambda that would be `(x) -> x.equals(gametype);`. The second filter would be a lambda with .equals(platform), called on the array spit out by the first filter. – cptwonton Feb 05 '18 at 14:52
  • https://www.sitepoint.com/java-8-streams-filter-map-reduce/ – cptwonton Feb 05 '18 at 14:52