Posted 31 May 2013 - 08:44 PM
Hey everyone
I just found out about CC recently after learning about lua through another game and looking around for other things with lua integrated similarly. After fooling around a bit with computers and turtles, I saw that nobody had created anything like this yet (or at least didn't share it), so in an effort to learn lua and CC, I created this program.
Basically, this program allows a turtle to create a sokoban level. It reads the level from a file, parses it, and builds it. After it's done being built, the turtle returns to the start position of the level, waiting for a wireless connection from a computer to begin playing the level. The turtle can build the levels vertically or horizontally, and can play them either way as well. Everything described works as it's supposed to, but it's not optimized completely. Building horizontally is faster than vertically, and playing the game isn't exactly fast-paced, because the turtle itself actually moves around to determine valid moves. It might be worth mentioning that the levels can be built with whatever materials you wish, you just need to put them in the correct columns in the turtle. The first inventory column is for the walls, the second is for boxes, the third is for goals, and the fourth is for boxes that are on top of goals. It is probably a good idea to make sure the inventory has at least one block of each type in the first row before beginning playing, as it continues use of these blocks to determine valid moves and when the game has been won.
The computer connecting to the turtle is expected to have 5 buttons connected to it, 4 for directions (up, down, left, and right), and a reset button (allows the computer to stop waiting for commands, and tells the turtle to stop listening to commands if it's connected). At this point in time, the inputs to the computer are hard coded, but I'm planning on making it able to be customized. Where each input is expected to be is described in the corresponding file (described below). EDIT: You can now control the turtle through the computer by using the arrow keys instead of buttons (see below)
There are 85 levels included, the format is condensed, each line is considered a different level. Vertical pipes ( | ) separate rows of the level, and different symbols correspond to the objects in the game: (-) = space; (#) = wall; ($) = box; (.) = goal; (@) = player start; (*) = box on goal; (+) = player start on goal (i think that's all). Numbers preceding a symbol tell how many of the next symbol to repeat.
There are 3 files: sokoban, sokoban_controller, and default.sok. sokoban is the main program, run this on the turtle. sokoban_controller is for the computer. default.sok is the file with the 85 levels. I made a new folder in the 'rom/programs/' directory called 'sokoban', and the path in sokoban near the top of the file reflects that. If you put the files in a different location, just change it here, or it won't be able to find the default levels if it can't read a file you specify. More detailed descriptions of each file and how to set up the computer for connecting with the turtle are in comments at the beginning of the files. If you need help getting the computer set up right, I can post a screenshot of how I did it. But anyway, here are the files:
http://pastebin.com/LQLuXKk5 - sokoban
http://pastebin.com/naxCyVLC - sokoban_controller
http://pastebin.com/V9detkFJ - default.sok
http://imgur.com/a/Fux7b - screenshots, including levels and button setup for the computer
EDIT: I forgot to mention, to use the program, simply cd to the folder with the file, and call it with the syntax 'sokoban <level> [path] [-v]', where level is a positive integer, path is an optional file path to the file you want to load the level from (instead of the default), and -v is the option to build the level vertically. For the computer, simply call 'sokoban_controller <port> <turtleID> [-d/b]', where port is the position you put the wireless modem, turtleID is the ID of the turtle you want to connect to, and -d or -b is the option to use the arrow keys instead of buttons or both methods, respectively. Currently, the button inputs are hard coded, so the only position you can put the wireless modem is 'top', unless you use -d, then you can put it wherever you want.
The main attraction here is the turtle building and allowing playthrough of the level, but if the main sokoban program is run on a computer (not sokoban_controller), it prints out the level to the console. This can help with debugging if you designed your own levels, but eventually I may make it possible to play through the console. My main focus was getting the turtle to build and be able to play the levels, and this is what I present to you today.
Try it out, find some bugs for me to fix, ask me some questions, suggestions, complaints, or whatever, and I'll do my best to respond.
Have fun!
I just found out about CC recently after learning about lua through another game and looking around for other things with lua integrated similarly. After fooling around a bit with computers and turtles, I saw that nobody had created anything like this yet (or at least didn't share it), so in an effort to learn lua and CC, I created this program.
Basically, this program allows a turtle to create a sokoban level. It reads the level from a file, parses it, and builds it. After it's done being built, the turtle returns to the start position of the level, waiting for a wireless connection from a computer to begin playing the level. The turtle can build the levels vertically or horizontally, and can play them either way as well. Everything described works as it's supposed to, but it's not optimized completely. Building horizontally is faster than vertically, and playing the game isn't exactly fast-paced, because the turtle itself actually moves around to determine valid moves. It might be worth mentioning that the levels can be built with whatever materials you wish, you just need to put them in the correct columns in the turtle. The first inventory column is for the walls, the second is for boxes, the third is for goals, and the fourth is for boxes that are on top of goals. It is probably a good idea to make sure the inventory has at least one block of each type in the first row before beginning playing, as it continues use of these blocks to determine valid moves and when the game has been won.
The computer connecting to the turtle is expected to have 5 buttons connected to it, 4 for directions (up, down, left, and right), and a reset button (allows the computer to stop waiting for commands, and tells the turtle to stop listening to commands if it's connected). At this point in time, the inputs to the computer are hard coded, but I'm planning on making it able to be customized. Where each input is expected to be is described in the corresponding file (described below). EDIT: You can now control the turtle through the computer by using the arrow keys instead of buttons (see below)
There are 85 levels included, the format is condensed, each line is considered a different level. Vertical pipes ( | ) separate rows of the level, and different symbols correspond to the objects in the game: (-) = space; (#) = wall; ($) = box; (.) = goal; (@) = player start; (*) = box on goal; (+) = player start on goal (i think that's all). Numbers preceding a symbol tell how many of the next symbol to repeat.
There are 3 files: sokoban, sokoban_controller, and default.sok. sokoban is the main program, run this on the turtle. sokoban_controller is for the computer. default.sok is the file with the 85 levels. I made a new folder in the 'rom/programs/' directory called 'sokoban', and the path in sokoban near the top of the file reflects that. If you put the files in a different location, just change it here, or it won't be able to find the default levels if it can't read a file you specify. More detailed descriptions of each file and how to set up the computer for connecting with the turtle are in comments at the beginning of the files. If you need help getting the computer set up right, I can post a screenshot of how I did it. But anyway, here are the files:
http://pastebin.com/LQLuXKk5 - sokoban
http://pastebin.com/naxCyVLC - sokoban_controller
http://pastebin.com/V9detkFJ - default.sok
http://imgur.com/a/Fux7b - screenshots, including levels and button setup for the computer
EDIT: I forgot to mention, to use the program, simply cd to the folder with the file, and call it with the syntax 'sokoban <level> [path] [-v]', where level is a positive integer, path is an optional file path to the file you want to load the level from (instead of the default), and -v is the option to build the level vertically. For the computer, simply call 'sokoban_controller <port> <turtleID> [-d/b]', where port is the position you put the wireless modem, turtleID is the ID of the turtle you want to connect to, and -d or -b is the option to use the arrow keys instead of buttons or both methods, respectively. Currently, the button inputs are hard coded, so the only position you can put the wireless modem is 'top', unless you use -d, then you can put it wherever you want.
The main attraction here is the turtle building and allowing playthrough of the level, but if the main sokoban program is run on a computer (not sokoban_controller), it prints out the level to the console. This can help with debugging if you designed your own levels, but eventually I may make it possible to play through the console. My main focus was getting the turtle to build and be able to play the levels, and this is what I present to you today.
Try it out, find some bugs for me to fix, ask me some questions, suggestions, complaints, or whatever, and I'll do my best to respond.
Have fun!