-6
\$\begingroup\$

i would like to code a single player game where at each turn a player has to write a letter on a grid. In response the computer would write a letter and so on. As soon as a word is created as a result of writing a letter, the player gets as many points as the no of letters in the word. how would i code it.

\$\endgroup\$
  • 3
    \$\begingroup\$ You should start coding by your self and then ask for a particular problem if it occurs. But basically you need to generate a random letter, get human input, check the string toward a dictionary and then start over. \$\endgroup\$ – danijar Dec 25 '12 at 22:03
  • \$\begingroup\$ meta.gamedev.stackexchange.com/questions/171/… \$\endgroup\$ – Tetrad Dec 26 '12 at 4:03
1
\$\begingroup\$

That’s a pretty easy almost-infinite loop. The main loop is something very common in game programming.

In Pseudo code:

playerTurn = 1 // playerTurn = 1 means its players turn, = 0 means computers turn

somebodyWon = False

while somebodyWon = False:
    if playerTurn:
        askPlayerForInput()
    else:
        writeInputFromComputerArtificialIntelligence()
    somebodyWon = checkIfSomebodyHasWonByUsingADictionary()

As you see, you need several components here:

  • Main class where you handle this loop
  • Some input for the player to input a letter (e.g. scanf() in C or StreamReader in Java)
  • Some easy artificial intelligence for the computer (he could search for words in his dictionary and add one letter for some real word he sees in the dictionary). Ideally, the computer should only know a subset of all real words. This could depend on the difficulty of your game (e.g. on very easy it knows 10% of all words, on very hard it knows 90% of all words)
  • A check for the input word against a list of winner words: Just take the word player + computer have already created and search in a dictionary (list of all real words) for it. If it is there, somebody has won.
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.