Author Topic: Goplat's 15Puzzle for TI-nspire Lua  (Read 13896 times)

0 Members and 1 Guest are viewing this topic.

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: 15Puzzle for TI-nspire Lua
« Reply #15 on: March 28, 2012, 09:09:25 am »
I think I know what modulus does now!
Created some sort of a guide here: http://ourl.ca/15687.new#new

Now, I did find a definition for .. but still have little idea what it means
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline someone

  • LV3 Member (Next: 100)
  • ***
  • Posts: 49
  • Rating: +9/-0
    • View Profile
Re: 15Puzzle for TI-nspire Lua
« Reply #16 on: March 28, 2012, 11:30:47 am »
Concatenates two strings (joins them together into a single one)


Edit: So for the following code:
Code: [Select]
local str = Moves .. " moves"
Moves is a variable that contains the number of times you've moved a piece
" moves" is a string & remains the same

Let say Moves = 200, so the string is equivalent to:
"200 moves"
« Last Edit: March 28, 2012, 11:38:04 am by someone »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: 15Puzzle for TI-nspire Lua
« Reply #17 on: March 28, 2012, 04:06:24 pm »
Ah ok thanks for the info. I hope TI won't start breaking stuff in the future, like Notch is doing with Minecraft now x.x (or what TI did with OS 2.53MP)

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: 15Puzzle for TI-nspire Lua
« Reply #18 on: March 28, 2012, 04:34:54 pm »
Well, I can assure you TI is did much work to keep <3.1 Lua scripts work fine on 3.2. They are clearly dedicated to this, so I wouldn't worry that much.

Offline cyanophycean314

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 363
  • Rating: +43/-1
  • It's You!
    • View Profile
Re: 15Puzzle for TI-nspire Lua
« Reply #19 on: March 28, 2012, 06:09:51 pm »
Exactly how would you create a batch file for Luna? I don't really know how to take arguments for .bat

Nice job with the 15-puzzle, no wonder it didn't work before.  <_<

Good luck with learning Lua!
« Last Edit: March 28, 2012, 06:10:06 pm by cyanophycean314 »

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: 15Puzzle for TI-nspire Lua
« Reply #20 on: March 28, 2012, 07:35:55 pm »
Why do you need a bat file ?

Luna just works like that  :

luna[.exe] source.lua output.tns

:)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline cyanophycean314

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 363
  • Rating: +43/-1
  • It's You!
    • View Profile
Re: 15Puzzle for TI-nspire Lua
« Reply #21 on: March 28, 2012, 09:49:41 pm »
Well, it'd be a lot easier if you don't have to open command prompt and type it in every time. Typing it in every time is slow... I run nspire_emu with a .bat too!

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: 15Puzzle for TI-nspire Lua
« Reply #22 on: March 29, 2012, 05:40:18 am »
Why do you need a bat file ?

Luna just works like that  :

luna[.exe] source.lua output.tns

:)
I had an answer in quick reply ready to go but then I refreshed the page :( (This reply isn't as good as my original one)
With cmd you'd have to navigate to the particular folder every time just to run Luna! I do not want to do that!
A slightly quicker way is to Shift +Click the folder but you'd have to go up a directory and still type in the stuff. A bit fiddly

So using a .bat file makes sense, in fact I can see no way of me using the cmd due to the fiddly methods above.

Here is the bat file code:
Code: [Select]
@echo off
set /p luafile= Type the lua filename (without extension):
set /p tnsfile= Type the tns filename (without extension):
luna.exe %luafile%.lua %tnsfile%.tns
@cyanophycean314 I used Levak's Batch File as a guide and just modified it to suit Lua! Though I don't completely get what "set /p" means

Just a few lines of code makes things much easier and logical :)


Concatenates two strings (joins them together into a single one)


Edit: So for the following code:
Code: [Select]
local str = Moves .. " moves"
Moves is a variable that contains the number of times you've moved a piece
" moves" is a string & remains the same

Let say Moves = 200, so the string is equivalent to:
"200 moves"
Thanks someone, I did see the word concatenates when I was searching and had no idea what it meant!
« Last Edit: March 29, 2012, 05:45:04 am by Jonius7 »
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: 15Puzzle for TI-nspire Lua
« Reply #23 on: March 29, 2012, 11:39:10 am »
Hopefully, all the hassles so far to create Lua scripts won't exist anymore with the 3.2 Lua SDK ;)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: 15Puzzle for TI-nspire Lua
« Reply #24 on: March 29, 2012, 02:02:50 pm »
Ha, I'll stilll use Luna+shellscripts+TiLP. Nothing beats that!
I have EEPro building integrated in my editor (geany), and with one press of a button it builds EEPro (which exists out of many seperate lua files) and uses TiLP to send it to my CX (or uses PCspire).
Just awesome :)

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: 15Puzzle for TI-nspire Lua
« Reply #25 on: March 29, 2012, 02:10:05 pm »
Quote from: Adriweb
Hopefully, all the hassles so far to create Lua scripts won't exist anymore with the 3.2 Lua SDK ;)
Quote from: jimbauwens
Ha, I'll stilll use Luna+shellscripts+TiLP. Nothing beats that!
Indeed, +1 Jim.

Until TI makes portable, scriptable tools that work for all of Windows, MacOS X, Linux and some popular BSDs - i.e. certainly never - there's no way all hassles can disappear ;)
Scriptability, and separation between GUI front-ends and worker backends with a CLI (or at the very least, libraries for encapsulating the worker backends), is a very important feature; the tools whose maintenance I have inherited are not scriptable enough (though TILP happens to be scriptable enough to fulfill Jim's use case, its CLI is very limited)...
« Last Edit: March 29, 2012, 03:54:10 pm by Lionel Debroux »
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: 15Puzzle for TI-nspire Lua
« Reply #26 on: March 29, 2012, 06:08:42 pm »
Lionel, totally agreeing with you about Linux... (but it's great they at least have a Mac version working...)

What I mean by the hassles disappearing, is that with one-click too, you are able to update your code within TINCS, and it can't be faster i any other way.
But of course, jim's scripts are better for "building" and on-calc testing all in one click :)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: 15Puzzle for TI-nspire Lua
« Reply #27 on: April 04, 2012, 02:17:29 am »
Anyway good to see that we won't have to take to such measures of making Lua scripts run in the future and can even edit the file directly (which means even better than Oclua on calc!). But to get back on topic
I want to try and understand completely what Goplat's 15 puzzle means. I've already learnt quite a bit, let's see what else there is. I have commented on this within the code :D
Code: [Select]
function on.charIn(ch) --called when a character key is pressed
if ch == "r" then --when r is pressed
board = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 } --this is how you create arrays!
-- Randomize
local swaps = 0  -- a local variable (wonder why)
for i = 1, 16 do   -- ah this is the For...To syntax in TI-84 and Casio basic and other stuff
local j = math.random(i, 16)  -- local variable, random number from i to 16
if i ~= j then  -- i not equal to j
board[i], board[j] = board[j], board[i]     --swap number in position i and j?
swaps = swaps + 1  --swaps number of turns
end
if board[i] == 16 then  --reach the end
empty = i 
end
end

-- If the number of swaps plus the number of empty-space movements is odd,
-- then the puzzle is impossible, so do an impossible move to make it possible
-- (exchange the space with a tile two squares away)
if (swaps + (empty - 1) + math.floor((empty - 1) / 4)) % 2 == 1 then   -- not 100% how this works, I know this is a way to fix an impossible puzzle :P
local i = (empty + 7) % 16 + 1
board[empty] = board[i]
empty = i
board[empty] = 16
end

moves = 0
platform.window:invalidate()  --force redraw of the screen calls on.paint(gc)
end
end

on.charIn("r")

function on.paint(gc)
local won = true
for i, n in ipairs(board) do
if n ~= 16 then
local x = (platform.window:width() - 128) / 2 + 32*((i - 1) % 4)
local y = (platform.window:height() - 128) / 2 + 32*math.floor((i - 1) / 4)
gc:drawRect(x, y, 30, 30)
gc:drawString(n, x + (30 - gc:getStringWidth(n)) / 2, y + 15, "middle")
end
won = (won and n == i)
end

local str = moves .. " moves"
gc:drawString(str, (platform.window:width() - gc:getStringWidth(str)) / 2, 0, "top")
if won then
str = "You win! Press R to reset"
gc:drawString(str, (platform.window:width() - gc:getStringWidth(str)) / 2, platform.window:height(), "bottom")
end
end

function on.arrowKey(key)
local dir
if key == "left" and empty % 4 ~= 0 then
dir = 1
elseif key == "right" and empty % 4 ~= 1 then
dir = -1
elseif key == "up" and empty <= 12 then
dir = 4
elseif key == "down" and empty > 4 then
dir = -4
else
return
end
board[empty] = board[empty + dir]
empty = empty + dir
board[empty] = 16
moves = moves + 1
platform.window:invalidate()
end
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)