What Is Game Pigeon 20 Questions

0. Background

A. Goals

The goal of this assignment is to provide a practical use of searching and sorting, while simultaneously building up familiarity with 2D arrays. In this assignment, you will build a modified version of the game 20 Questions. By the end, you will be familiar with:

Game Pigeon extension for iMessage offers various multiplayer games like Cup Battle, 20 questions, Checkers, 4 in a row, and others. Game Pigeon is specially developed for iMessages, and thus the graphics of this game are pretty neat. Have another go at the spectrum of FunTrivia categories! Twenty questions of random fun! Average score for this quiz is 13 / 20.Difficulty: Average.Played 2,388 times. As of Dec 23 20. Question: Q: Why can’t i download game pigeon? When I go to the App Store and search up game pigeon it’s shows up as “get”, when I click “get” it makes me type in my password as if I wasn’t signed into my Apple ID. Once I sign in it starts to download and then it stops and says “get” again.

  1. 2D arrays,
  2. selection and insertion sort conceptually and their implementations, and
  3. understanding how recursion is used to search for specific elements in a dataset.

B. Background

As a child, you may have played a game called “20 questions”, in which one player thinks of an animal, person, or object and the other person guesses the secret item by asking 20 questions. In this assignment you will be writing a modified version of this game. Your program will ask you to think of an animal, and then ask you up to N yes or no questions in order to guess the animal you're thinking of. The questions and possible outcomes will be determined through a dataset we provide.

An online example of the game 20 Questions can be found at www.20q.net.

C. Your Program

First, download the skeleton code for GuessingGame.java, the data sets animals_small.txt and animals.txt, and the library Prompter.java for getting interactive input.

By the end of the assignment, your program GuessingGame will (1) read in questions and answers data set from a file, (2) store the data in a 2D array, (3) sort the data so it can be easily searched, and (4) interact with the user to search for a target item. It will prompt the user with a number of questions until a single answer can be decided on. If there is no match the program should let the user know its been stumped.

The final product will look like:

1. Reading the Data

A. Data Format

Before you can start asking and answering questions, your program will need to have a large set of animals and some information about them. To do this, you’ll read in a file in the following format:

animals_small.txt:

First, it provides the number of animals and questions in the data set. Then all the questions, each on their own line, and finally a list of animals and the answers to the questions ('y' is for yes; 'n' is for no). For instance, if you look at the line owl n y n, the first column is the name of the animal (owl), the second is the answer to the first question (an owl is not a mammal), the third to the answer to the second question (owls are carnivores), and the last is the answer to the third question (owls do not stand on four legs). Once you feel comfortable with the format of the data, move on to the next section.

B. readData()

Now that you know what format the data will be in, you will write the function, readData(String filename), to parse through the animal.txt file.

readData() should be doing two things: 1.) initializing and populating a class-level array called String[] questions, and 2.) initializing and populating a class-level 2D array String[][] answers. Note that in the skeleton code we provided, readData() has a void return type, so you should not be returning either questions or answers.

After running readData(“animals_small.txt”), your arrays should contain:

Note that each row (the first index) in answers corresponds to an animal, and each column (the second index) corresponds to an answer to a question (or the animal's name). Be careful -- it is very easy to mix this up. For reference, you can access a particular animal's attribute via answers[animalIndex][questionIndex], where animalIndex and questionIndex are the indices of the animal and question respectively (write this down somewhere!).

If you need a reminder how to read in from files, look back at previous homework assignments and read about In inStream. Once you believe your readData() is correct by eye, write the print() function in the next section and then test your two functions in main().

C. print()

Being able to easily debug is essential when writing large programs. With this in mind, write a print() function that outputs the content of the two class-level arrays.

print() should print 1.) the number of animals, 2.) the number of questions, 3.) the questions array, and 4.) the answers array. The output should look EXACTLY like the file you read in, but you should construct this output based solely on the questions and answers arrays. Be sure that each animal has all its info on the same line in your output, and compare it to the original file.

To check whether your program is correct so far, write a short main() function to first call readData('animals_small.txt') and then print(). Make sure that the output is identical to the content of the animals_small.txt file. Once you can successfully do this, move on to the next section.

2. Sorting the Data

The next step is to sort the data set so that we can use standard searching techniques efficiently. However, unlike the sorting code we covered in class, we now have to deal with the 2D structure of the array AND the fact that we will be asking multiple questions.

Essentially, we need to reorder the rows (i.e., animals) so that each column is in sorted order, subject to row-order of the previous questions.

This complex idea should be easier to understand with an example. Imagine that we have the following small data set

We must first re-order the rows so that the first column is in sorted order:

This effectively divides the data set into two parts (blue and red), depending on the answer to the first question. Then, we have to re-order the rows WITHIN the blue and red blocks such that the 2nd column is in order:

Now, we effectively have four blocks, corresponding to the values of the first two attributes (nn, ny, yn, yy):

Next, we must sort the rows WITHIN each of these four blocks by the third column, yielding:

Notice that we reorder the rows WITHIN each block, but NEVER ACROSS blocks. We would then keep repeating this process for all subsequent attributes.

Read this example over several times until you thoroughly understand it. Once you do understand conceptually how this sort must work, move onto the next section.

B. Sorting in sort()

To do this sort, you will write several functions.

The first function you should write is:

public static void sortRange(int startingAnimalIdx, int endingAnimalIdx, int questionIdx)

This should sort the rows in the 2D array answers from row indices startingAnimalIdx to endingAnimalIdx (not including endingAnimalIdx) based on the column at index questionIdx. For instance, if answers looks like

and you called sortRange(0, 2, 2), you would be sorting the first two rows by the second column:

Game pigeon 20 questions

We can see that 'n' is earlier in the alphabet than 'y', and so these two rows should be switched, resulting in:

You are free to write this sorting function using either insertion sort or selection sort. You can look at the lecture materials to see a code implementation of either sort for 1D arrays, and you can base your code off the lecture code. However, not that your code will be substantially different from the lecture code since it must deal with the 2D structure of the array.

For comparing values, you should be using the String.compareTo() function to compare the Strings. With Strings a and b, a.compareTo(b) will return a negative number if a < b, positive if a > b, and zero if they are equal.

Once you can sort a column within a particular range of rows, you can move on to the next section. Write some code in main() to test your implementation. Remember, if you are having trouble debugging, use the print() function to help figure out what is going wrong! Make sure it works correctly before moving onto the next part.

C. Finding the Split

We have one more helper function to write before we can do a complete sort through the data set. For every question, once we use sortRange() to sort answers by a question, there will be an animal where everything above it answers 'n' to question and everything below has answers 'y'. You will want to write the function

public static int findSplit(int startingAnimalIdx, int endingAnimalIdx, int questionIdx)

that will find the index of the first animal row that has the answer 'y' to the question questionIdx within the range startingAnimalIdx to endingAnimalIdx (not including endingAnimalIdx). Note that this is a bit different than the standard binary search we discussed in class.

You should be comfortable with the intuition of binary search before you start coding!

Remember you will want to find the midpoint, and depending on the answer to the questionIdx at that row, you will want to recurse either to the top or bottom half of the search range. You will need to check the value immediately below the midpoint in order to determine if it is the first 'y' to appear. If all of the answers in the range are 'y' or all are 'n', you'll want to return -1.

Once you have this, you should be able to test it on animals_small.txt. For example, findSplit(0, 4, 1) should return 2.

If you are unable to get binary search working to find the split point, you may use linear search for partial credit.

D. Recursing in sort()

Once sortRange() and findSplit() are done, we then want to sort the entire answers array, starting at the first question and then moving onto subsequent questions, exactly as in the example at the top of this section. This will be done recursively, which means writing a base case and recursive calls within the sorting code.

Write a recursive helper function public static void sort(int startingAnimalIdx, int endingAnimalIdx, int startingQuestionIdx) to implement this sorting process. Note that this has a very similar signature to sortRange() but behaves very differently in one respect -- this function sorts the given range of animals COMPLETELY, starting with the column index startingQuestionId and moving onto all SUBSEQUENT columns. (In contrast, sortRange() only sorts the given range for that particular column.)

Base Case: The base case is if the question you are sorting by does not exist (i.e., you only have 3 questions but you are trying to sort based on the 4th question) OR if there is only one row remaining in the given range. In this case, you simply want to return without doing anything.

Recursive Calls: For each column, you’ll want to make two recursive calls. Say, in animals_small.txt you have split the group into mammals and non-mammals:

Next you want to look at only the non-mammals and split it by whether they are carnivores, then look only at the mammals and split by whether they are carnivores.

Following that intuition, we will want to do two recursive calls for every column, one for the 'n's, and one for the 'y's. So for each, you should find the top and bottom of the range to pass as the startingAnimalIdx and endingAnimalIdx arguments to sort() (Note: this is where findSplit comes in!). Remember to deal with the edge case where findSplit returns -1. Within the mammals, you don’t want to sort by the mammals question again, so your question argument shouldn’t be the same, but should move to the next question (question + 1).

Once you have finished and tested this recursive helper function, you should go back implement the sort() function to recursively sort all columns of answers. Think about what the initial range of the sort should be, and the first question that it should be sorted by.

3. Searching the Data

A. Narrowing the Possibilities

Now that we have our data ordered, we can quickly search through it. Consider the animals in animals_small.txt:

Before your first question, all you know is that your search range is the entire list of animals. Once you ask the first question, and know that the animal is a mammal, your search range suddenly gets chopped in half:

This process is very similar to the binary search you talked about in lecture and implemented in findSplit , although the split won't always be perfectly in half.

In order to make GuessingGame interactive, we've provided the Prompter.java library. It has only one function:

String prompt(String prefix)

What Is Game Pigeon 20 Questions Asked

If you call Prompter.prompt('> ') it will print '> ', wait for the user to enter a String, and then returns that String.

Once you feel comfortable with the conceptual side of this search, move on to write search().

B. search()

You now have all the pieces in place to begin guessing some animals! Similarly to sort(), you will see there are two functions in your skeleton code called search.

First, let’s look at:

public static String search(int startingAnimalIdx, int endingAnimalIdx, int questionIdx)

This function should search through your data set, considering only the range from startingAnimalIdx to endingAnimalIdx, looking first at questionIdx. As in other functions, animals[endingAnimalIdx] is not included in the search range. It will be structured as a binary search. If you'd like a refresher, you should look back a the lecture material on binary search (there is even a code implementation there!).

search() will be recursive, so you will need a base case and recursive calls:

Base Case: The base case is when there is only one element in your search range. Note that the answers[endingAnimalIdx] row is not in the search range. You should return the single element's name (the actual name of the animal found in the zeroth column).

Function Body: You should System.out.println the question text and then use Prompter.prompt('> ') to get the answer.

Recursive Call: First find the 'n' and 'y' split using findSplit, then, if the user answered 'n', search from the startingAnimalIdx of the range to where the split is. If the user answered 'y', search from the split to the endingAnimalIdx of the range. You will also want to move on to the next question (question + 1).

What Is Game Pigeon 20 Questions 2019

Once you have finished this function, complete:

public static String search()

It should be only one line long and call search(int startingAnimalIdx, int endingAnimalIdx, int questionIdx) and search the entire list starting with the first question.

If this is done correctly, you should be able to play the game with the following code in your main():

How Do I Delete Game Pigeon

4. Extra Credit

A. Create Your Own Dataset!

For extra credit, you can collect your own dataset to query using your program! Make sure it adheres to these rules:

  1. No two items should have the same set of answers. For instance, a bear and a lion are both carnivorous mammals that stand on four feet, so with the questions in animals_small.txt we wouldn’t be able to differentiate them.
  2. All answers should be “yes” or “no”, and so all questions should be yes-no questions.
  3. The data set should contain at least 50 items

Before you submit, make sure your dataset works with your Program!

5. Submission

A. README

Complete readme_guessing.txt in the same way you have done for previous assignments.

B. Submission

Submit GuessingGame.java and readme_guessing.txt on the course website. If you have completed extra credit please mention this in the readme, and submit it compressed as extra.zip.

Before submission remove any print statements that were used for debugging or testing your functions.
Be sure that every method has an appropriate header comment, and that your code is well-documented.

  • Gamepigeon - 8/10
    8/10

Summary

Name of App: Gamepigeon
Type Of Game: Imessage Game
Category: Game
Type of License: Free
Seller: Vitalii Zlotskii
Size: 59.8 MB

[maxbutton id=”61″ url=”https://itunes.apple.com/us/app/gamepigeon/id1124197642?platform=iphone&preserveScrollPosition=true#platform/iphone”]

Gamepigeon is basically a free iMessage extension for iOS. The extension lets you play ad experience some very fun multiplayer games over iMessage with your friends and other online players from all over the world. It comes with a rich graphical and easy to use interface which makes the gaming experience a whole lot better and engaging. The app is compatible with iOS 10.0 or later versions and is available in English, French, German, Japanese, Korean, Portuguese, Russian, Spanish and Chinese. Lastly it comes with a number of variant games to fit players from different genres.

The games are namely :

  • 8-Ball
  • Tanks
  • Basketball
  • Mancala
  • Cup Pong
  • Sea Battle
  • Mini Golf
  • Anagrams
  • Reversi
  • Gomoku
  • Four in a Row
  • Knockout
  • Chess
  • Checkers
  • 20 Questions
  • 9-Ball
  • Filler
  • Word Hunt
  • Shuffleboard
  • Crazy 8

FEATURES

  • Free
  • Safe and Secured
  • Size 59.0 MB
  • Smooth and Easy User Interface
  • Offers In-App Purchases
  • Supported in iOS 10.0 and higher versions
  • iMessage Extension

Alternatives To Gamepigeon

In today’s world where messages are always difficult to keep private and secured from others, Confide comes as a savior. Apple’s Confide app lets you communicate…