Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
21 May, 2013, 05:49:53 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1] 2 3   Go Down
  Print  
Author Topic: Scramble/Boggle Lua -  (Read 1446 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
cyanophycean314
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 03 May, 2013, 19:28:34
Date Registered: 07 December, 2011, 02:44:32
Location: Somewhere?
Posts: 363


Topic starter
Total Post Ratings: +42

View Profile
« on: 30 June, 2012, 20:53:49 »
+2

Because I recently got Scramble with Friends for my Android tablet, I took it upon myself to make this game. Right now, the screenshot shows most of what it can do. I may enter this for the contest if I can code an AI to be your "friend." You'll have the option to watch him play.

Right now the biggest problem is the dictionary. I've googled online for a dictionary and it was 170,000+ words. I tried to put that into my Lua file, but it said there was not enough memory  Tongue. So the dictionary right now is all the words I can think of.

I still need to add a solver to find all possible words, change the scoring scheme to be more like Scramble (without double/triple), add some results page, randomly generated puzzles, and get the dictionary working.

Hope you guys enjoy.


* scramble1.gif (674.39 KB, 320x240 - viewed 313 times.)
Logged

adriweb
Editor
LV9 Veteran (Next: 1337)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 00:38:33
Date Registered: 13 April, 2011, 18:42:59
Location: South of France
Posts: 1196


Total Post Ratings: +185

View Profile WWW
« Reply #1 on: 01 July, 2012, 15:46:24 »
0

Very nice ! Cheesy
Logged


TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation
shmibs
bonsai bok choy wiseguy waterboy
Administrator
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Last Login: Today at 04:46:47
Date Registered: 11 June, 2010, 19:36:15
Location: 89B6
Posts: 1842


Total Post Ratings: +229

View Profile
« Reply #2 on: 01 July, 2012, 17:08:14 »
0

would using some form of text compression slow things down too much, or would that plus a binary search be doable?
* shmibs has no clues about the speed of nspire lua
« Last Edit: 01 July, 2012, 17:08:32 by shmibs » Logged



We're not human, are we?
Jim Bauwens
Lua! Nspire! Linux!
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 00:39:35
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Total Post Ratings: +180

View Profile WWW
« Reply #3 on: 01 July, 2012, 18:48:49 »
0

Adding compression should not slow it down much.
Anyway, how do you store the data ? Just a large table ?
Logged

cyanophycean314
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 03 May, 2013, 19:28:34
Date Registered: 07 December, 2011, 02:44:32
Location: Somewhere?
Posts: 363


Topic starter
Total Post Ratings: +42

View Profile
« Reply #4 on: 01 July, 2012, 21:52:14 »
0

Currently all the dictionary is stored in a table, and I don't really know a better way to do that. I have binary search implemented so speed shouldn't be a problem, hopefully. I have no idea about compression...
Logged

Loulou 54
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 19 May, 2013, 15:27:36
Date Registered: 22 July, 2011, 21:19:29
Location: Meurthe-et-Moselle FRANCE
Posts: 152


Total Post Ratings: +34

View Profile WWW
« Reply #5 on: 21 July, 2012, 15:34:01 »
+1

Hello cyanophycean !

In TI-Translate, I stored the data in huge strings IN the TI Nspire document. (indeed I couldn't paste all into ONE string because the length of a string on the TI Nspire is limited ! So I had to split my list into small pieces ! (516 words per string if I remember, or 516*84 characters)) That was rather complicated and I had to make a kind of a script to automate "copy/paste"s from notepad to the student software.. %)
Why such a weird and difficult solution ?
Because my strings contained a lot of accentuated characters and the TI Nspire scripting tool made shit.. (just closed the Student Software every time I pasted the code !)
(I also tried with Luna, and the generated file produces an error too..)

About memory problems : my biggest version (english/french) contains 58 959 words from english to french AND 56 252 words from french to english. Moreover, the storage isn't really optimized... Actually each word takes exactly 84 characters and the remaining place is filled with blanks.
An extract :
Quote
a b c {m} [abécédaire]         primer {n} [ABC]                                     a latere [REL‚ loc adj]        a latere [adj phr]                                   a latere [REL‚ loc adv]        a latere [adv phr]                                   a priori [loc adj]             a priori [adj]                                       a priori [loc adv]             a priori [adv], guess; at a ~ [adv phr]              a priori {m inv}               apriorism {n}, preconception {n}                     A {m} [alphabet latin]         A {n} [Roman alphabet]                               A {n} [ÉLEC‚ ampère]           amp {n} [ELEC‚ an ampere]                            abaissement {m}                abatement {n}, decay {n}, lowering {n}               abaisser [v tr]                lower [v tr‚ make lower]                             abaisser [v tr‚ raccourcir]    cut up [v tr]                                        abaisser [v tr‚ réduire]       bring down [vt‚ lower a price]                       abaisser; s'~ [v pr]           off; to get ~, demean; to ~ oneself                  abaisser; s'~ vivement [v pr]  duck down [v intr]                                   abaisser; s'~ à faire          stoop; to ~ to doing                                

This was the original format of the data from Freelang dictionnaries. On the other side, this format was convenient to navigate through the list because you just have to make 84 characters steps to get the next word ! Smiley

So, here is how it works for my TI translate ! ^^

In term of number of characters, it represents for both lists 9 677 724 characters !

So if you want to solve your problem, maybe you could do as I did, but I don't think that's the best solution. Moreover you don't need here the assets of this solution, as I did. (storing in a string to ease the string research, supporting accentuation,...)

So I think that the easier solution is to reduce the amount of word ! Tongue

PS : have you tried to split your table into smallest ones ? (maybe it's the length of a table wich is limited..)

Anyway, good luck ! Cheesy

EDIT :
Your program must search words in your list actually ? How do you do that with your table ? You scan the whole table to see if it contains the word ?
« Last Edit: 21 July, 2012, 15:39:38 by Loulou 54 » Logged

Some of my program available here.. Smiley
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471

     
cyanophycean314
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 03 May, 2013, 19:28:34
Date Registered: 07 December, 2011, 02:44:32
Location: Somewhere?
Posts: 363


Topic starter
Total Post Ratings: +42

View Profile
« Reply #6 on: 21 July, 2012, 15:59:42 »
0

Thanks Loulou for the explanation and suggestions.  Smiley

I'll try splitting up my table into smaller ones, probably divided by letters. Or I could also use strings like you did.

I planned on using binary search to go through my list and find the word, but now I just realized that there were string search functions provided by Lua.
Logged

Nick
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: Yesterday at 20:44:19
Date Registered: 05 June, 2011, 20:01:07
Location: 51° 12′ 34″ N, 3° 13′ 31″ E
Posts: 1178


Total Post Ratings: +158

View Profile WWW
« Reply #7 on: 22 July, 2012, 11:26:00 »
0

wow, this is a great game Shocked maybe you could just use semicolons (Wink to split words, and the look for the matching ; so split them up, that would be the most easy way i think..

is it correct if i saw that you don't get extra points if you make a word you already formed, or did i just look bad?

how do you make the grid? because you say 'randomly generate ouzzles', does that mean you now just make them by hand and type them in?
Logged

cyanophycean314
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 03 May, 2013, 19:28:34
Date Registered: 07 December, 2011, 02:44:32
Location: Somewhere?
Posts: 363


Topic starter
Total Post Ratings: +42

View Profile
« Reply #8 on: 23 July, 2012, 15:07:34 »
0

Thanks.  Smiley

What exactly do you mean when you said to use semicolons to split words? To select words, you press the tab button, and then use the numpad to move along the board, selecting letters as you go. Then you release tab, and that's your word.

The program checks if you've already used that word.  Smiley

Currently this is just a hard-coded grid, but I'm working on random generation (balancing it is kinda tricky...).

Edit: Woah, it's my 300th post.
« Last Edit: 23 July, 2012, 15:08:17 by cyanophycean314 » Logged

Nick
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: Yesterday at 20:44:19
Date Registered: 05 June, 2011, 20:01:07
Location: 51° 12′ 34″ N, 3° 13′ 31″ E
Posts: 1178


Total Post Ratings: +158

View Profile WWW
« Reply #9 on: 23 July, 2012, 23:50:07 »
0

i meant that semicolon thing for your encoding of the library.

if you do for example lib = "can;pie;cake;board;door" etc you can easely split them up to find the words, and you don't need that endlessly long table to store your entries..
Logged

Loulou 54
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 19 May, 2013, 15:27:36
Date Registered: 22 July, 2011, 21:19:29
Location: Meurthe-et-Moselle FRANCE
Posts: 152


Total Post Ratings: +34

View Profile WWW
« Reply #10 on: 24 July, 2012, 00:31:53 »
0

binary search == dichotomy ?

i meant that semicolon thing for your encoding of the library.

if you do for example lib = "can;pie;cake;board;door" etc you can easely split them up to find the words, and you don't need that endlessly long table to store your entries..

Yes it could be a good solution, using the string.find function. Smiley
(Actually that's almost what I did for TI translate, but in Basic.)

Moreover this function provides very powerful features with what's called "patterns". You can look in the Lua manual to get more informations. Smiley

(little trick : if you want to convert your table into Nick's format, don't forget the "Replace" function of your notepad ! Wink I mean, for example : {"hello","world","I'm happy"} => Replace `","` by `;` => {"hello;world;I'm happy"} => then just delete the "{" and you have your string Smiley )
« Last Edit: 24 July, 2012, 00:33:31 by Loulou 54 » Logged

Some of my program available here.. Smiley
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471

     
3rik
LV3 Member (Next: 100)
***
Offline Offline

Gender: Male
Last Login: 02 April, 2013, 22:45:02
Date Registered: 09 August, 2011, 04:04:54
Location: Right over there.
Posts: 92


Total Post Ratings: +8

View Profile
« Reply #11 on: 24 July, 2012, 02:02:43 »
+2

If the plan is to have large dictionaries, this might be useful.  Smiley


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function editDictionary(dictionary, old_dict)
local data = old_dict or {}
for _, word in ipairs(dictionary) do
local curchar = data
for i = 1, #word do
local char = word:sub(i, i)
if not curchar[char] then
curchar[char] = {endof = i == #word and true or nil}
elseif not curchar[char].endof then
curchar[char].endof = i == #word and true or nil
end
curchar = curchar[char]
end
end
data.lookup = function(tbl, str)
local function lookup(str)
local curchar = data
for i = 1, #str do
curchar = curchar[str:sub(i, i)]
end
return curchar.endof
end
err, ret = pcall(lookup, str)
return err and ret or nil
end
return data
end

It takes a table like

1
2
list={"carbon","cars","car","cat","cats"}

and creates a table like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
dictionary = {
c={
a={
r={
b={
o={
n={endof = true}
}
}
s={endof = true}
endof = true
}
t = {
s={endof = true}
endof = true
}
}
}
lookup = function(tbl, str)
--blah blah blah
end
}



lookup takes a string and rapidly returns a true or nil value based on if the word is in the list of acceptable words.

Here's an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
dict = {"cat", "cats", "dog", "mouse"}

dictionary = editDictionary(dict)

print("d:", dictionary:lookup("d"))
print("do:", dictionary:lookup("do"))
print("dog:", dictionary:lookup("dog"))
print("dogs:", dictionary:lookup("dogs"))
print("dogz:", dictionary:lookup("dogz"))

amendment = {"dogs"}
dictionary = editDictionary(amendment, dictionary)
print("\nAmendment: dogs added!\n")

print("d:", dictionary:lookup("d"))
print("do:", dictionary:lookup("do"))
print("dog:", dictionary:lookup("dog"))
print("dogs:", dictionary:lookup("dogs"))
print("dogz:", dictionary:lookup("dogz"))

prints


1
2
3
4
5
6
7
8
9
10
11
12
13
14
d: nil
do: nil
dog: true
dogs: nil
dogz: nil

Amendment: dogs added!

d: nil
do: nil
dog: true
dogs: true
dogz: nil

What I like about this way is that it narrows the search down for each letter in the string instead of searching for the whole string in a giant table or string. It could be potentially bulky, though.

Worst case scenario, it could end up indexing something like dictionary.p.n.e.u.m.o.n.o.u.l.t.r.a.m.i.c.r.o.s.c.o.p.i.c.s.i.l.i.c.o.v.o.l.c.a.n.o.c.o.n.i.o.s.i. s.endof but most of that searching would be handled by Lua itself.

This is case sensitive, but if it makes a difference it would only take a simple metatable to fix.


EDIT: Reread the first post and testing a few things first
« Last Edit: 24 July, 2012, 02:08:32 by 3rik » Logged

Userbars
cyanophycean314
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 03 May, 2013, 19:28:34
Date Registered: 07 December, 2011, 02:44:32
Location: Somewhere?
Posts: 363


Topic starter
Total Post Ratings: +42

View Profile
« Reply #12 on: 24 July, 2012, 03:14:47 »
0

@3rik: Your solution is interesting, but I think memory constraints will occur... I'll give it a try if my current attempt fails.

Right now, I have around 1158 strings with format: words1 = 'aa;aah;aahed;' words2 = 'aahing;aardvark;'
The problem is that I want to go through the different strings. My current code is this:

1
2
3
4
5
6
7
8
9
10
11
function checkWord(word)
local letterkeys = {1,72,129,241,310,360,402,437,479,533,541,551,582,647,679,720,822,827,895,1019,1076,1112,1130,1152,1153,1155}
jstart = letterkeys[string.byte(word) - string.byte('a') + 1]
for i = jstart,1158 do
loadstring("abc = words"..i)
if string.find(abc,word) then
return true
end
end
return false
end

The letterkeys indexes a place for each letter, so the searching will go faster. Then it starts at that index and goes through each string and searches it using the string.find().

The loadstring thing doesn't work. It's purpose is to try and execute

1
abc = words12
or

1
abc = words13
depending on the value of i. This way I can avoid a big table that'll probably give me memory errors. It's basically like indexing without a big master table without a huge variable.

I'm not too familiar with loadstring, but it seems very powerful if it can be used like this.
Logged

3rik
LV3 Member (Next: 100)
***
Offline Offline

Gender: Male
Last Login: 02 April, 2013, 22:45:02
Date Registered: 09 August, 2011, 04:04:54
Location: Right over there.
Posts: 92


Total Post Ratings: +8

View Profile
« Reply #13 on: 24 July, 2012, 04:57:29 »
0

I tested this way on the student software and it took about 3 seconds to load my list of ~100,000 words and convert it to the table. From there it was able to index any word very quickly (including long words like symptomatologically). The overall memory is a tad bulky (but there's only so much you can shrink 100,000 words). Each key, however, only points to a table containing, at most, 27 new keys.

A warning: don't paste tables like this into programs bulky IDEs with syntax highlighting. I pasted a table into the student software, walked away for an hour, came back and it was still trying to highlight everything. I eventually gave up and used the old scripting tools to test out the method.

I'll attach the code I tried with.

EDIT: I just realized that there are two lists in this program. There is still a table with all 100,000 words in it. I haven't sent this code to my calculator, so I'm not 100% sure that there won't be any memory issues.

EDIT2: I just realized, if one wanted definitions included with this structure, the values of the endofs (or _s) would just need to be changed from true to the definition. This wouldn't really apply to Boggle, but it could be used elsewhere.

EDIT3: loadstring is intended to be more for accepting code from the user. oclua is a good example of this. Tables and strings should be able to handle this problem without loadstring.

* new 22.lua (1342.12 KB - downloaded 12 times.)
« Last Edit: 24 July, 2012, 18:57:37 by 3rik » Logged

Userbars
Nick
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: Yesterday at 20:44:19
Date Registered: 05 June, 2011, 20:01:07
Location: 51° 12′ 34″ N, 3° 13′ 31″ E
Posts: 1178


Total Post Ratings: +158

View Profile WWW
« Reply #14 on: 24 July, 2012, 18:22:03 »
0

A warning: don't paste tables like this into programs with syntax highlighting. I pasted a table into the student software, walked away for an hour, came back and it was still trying to highlight everything. I eventually gave up and used the old scripting tools to test out the method.

you probably never heard of notepad++ ?? it takes 0.00001 seconds to load, and it only loads the parts you see, so as you scroll it colors the part you see, so no unnecessary coloring happens Smiley
Logged

Pages: [1] 2 3   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.337 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.