mysql - How do I search for a 'blank tile' in a scrabble application? (PHP) -


I created this app a few months ago:

Allows the application to enter the set of users

Actually, what I want to do is to increase the application so that users can enter 'empty tile' - this is the one which can pass as any of the 26 letters of the alphabet, and Can be echoed back to valid words.

Below is a screenshot of database structure.

  http://i37.tinypic.com/28v6a8h.png  

You may have to copy that browser into your browser.

For the query example, 'Aardvark' - is as follows:

  Select * from Scrabble where a & lt; = 3 and b & lt; = 0 and c & lt; = 0 and D & lt; = 1 and E & lt; = 0 and f  

If you want to see results that I'm typing a word in the link posted at the top.

OK,

So does anyone have any idea how to do this? I started with the following code, which adds each alphabetical character at the end of the string entered by the user, if they enter spaces (empty tiled spaces)

  if (preg_match ('/ [\ s] /', $ string) $ $ wild_string = $ string; Forex Currency (Category ('A', 'Z') $ i) {$ wild_string = $ string; $ Wild_string = $ i; }  

The $ wild_string variable is that each letter is added to the loop. Resetting it to the initial string on each loop is prevented from adding the code to all the 26 characters on the string.

I hope someone can help, and I'm sorry if I'm waffle :)

Andy

My proposal is:

Assume that user input is: Ab * where * is wildcard. Calculate all known letters and wildcards and create an array where element 0 is the number of wildcards and each other element key is a known letter, which How often is given in user input:

  function GetArrayLetters ($ userInput) {... // $ characters = (0 = & 1; 'a' = & gt; 1 , 'B' = & gt; 1) Defense does; Return $ characters; }  

Modify your query by adding the number of wildcards on the length of each letter and word using that array:

  # with only one wildcard , Will be queryed: Selection * from Scrabble where a & lt; = 2 and b & lt; = 2 and c & lt; = 1 .... ... and length & lt; = 3  

Now put the result somewhere (an array) and check each word in turn and go through each letter and subtract one for each known letter from your $ letter array; If the value of a known letter is zero, then instead of subtracting element from 0 (wildcard). If you get a negative value for the wildcard, discard the word:

  foreach ($ result_set as $ word) {$ letters = GetArrayLetters ($ userInput); ($ I = 0; $ i & lt; str_len ($ word); $ i ++) {$ characters = substrate ($ word, $ i, 1); If (array_key_exists ($ letters, $ letters)) {if ($ letters [$ letters]) & gt; 0 {$ letters [$ letters] - = 1; } And {$ letters [0] - = 1; // subtract from other wildcards}} and {$ letters [0] - = 1; } If ($ letter [0] & lt; 0) {// wildcard becomes zero, leave the word}}}  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -