First Lua program--formatting text, color, background - arrays

I'm brand new here, and also to Lua, so please bear with me...
I'm building an Airport in Minecraft, with my kids. I'm an overachiever and a dreamer, and at some point, my brain decided it would be a FANTASTIC idea to add in a cosmetic element that I have absolutely NO idea how to do. Smart, right?!
See, I got it in my head that I want to have display screens in our Airport that show the flight information of incoming/outgoing flights. Fast forward to my discovery of the Opencomputers mod for Minecraft, a few hours of watching tutorials on how to operate it, and thus began my search for knowledge of that which is the Lua language. Fortunately, I have a wee bit of coding experience (thanks to my college days) and I picked up the very basic of the basics. (It seems similar to C.) I've gleaned just enough to accomplish the bigger part of my goal: I've managed to write the bare bones of the program I dreamed up, and it works...for the most part. (I still need to figure out some redundancies and such...all in good time.)
But...it's so very plain, and not fancy at all. It doesn't look even remotely like what I was picturing in my head, and this simply will not do. So now I am on a quest to discover how to format the output of my program and make it look fantastic...or at least, as close as I can get it to what was in my head. I have managed to figure out how to change the gpu screen colors (foreground, background) so that is why it's blue/white. But it's not quite what I wanted, and it resets if the system is turned off. My goal is to change the format of the program output itself, not just the Opencomputers screen block. I've googled this until I'm blue in the face, and I have pored over forums and code tutorials and the like...only to fail at finding the information I need. It's possible that I've passed up the answer, simply because I'm still very new to the language, but that's another good reason for me to be here, right?
And so, I turn to you, O Great Dwellers of the Interwebs, the Keepers of Vast Programming Knowledge, for assistance. Please, pretty please, help me make my program look awesome. My kids just may think I'm the coolest Mom on the planet, and that would be more than fantastic...Not to mention we'd have one kickass airport to play around in. :)
Here's what you'll probably want to know:
First, This pic is what I want, (on the left) and what I have (on the right).
And here is the code for my program: http://pastebin.com/60nPfpB8
I apologize up front for all of the noob mistakes that my code is more than likely riddled with. I haven't figured out yet how to make the functions repeat themselves, or a good way to utilize a 24 hour clock for the "time" function. So any suggestions there would be welcome as well.
Thank you for taking the time to read, and I appreciate any help I can get with this. :)

Related

How does Alexa's conversation flow work?

I want to write a quiz/interview game where the flow is like this:
"Alexa, start Movie Trivia."
Welcome to Movie Trivia. Do you need to hear the rules?
"No."
What category would you like to play? Comedy, drama, or animation?
"Comedy."
Question 1. In what year was Star Wars released? A, 1970. B, 1977. C, 1980.
"B."
Correct. Your score is 1. Question 2...
I managed to write spaghetti code to accomplish this, with lots of if session.attributes.category, if session.attributes.needsRules, etc stuff, 3 pages of nested if-elsing.
I'm using Node and the official Alexa SDK, so I read its documentation cover to cover, but it's quite confusing and broken in places (examples that haven't worked since June, instructions for old UIs and so on). My question is: what kind of flow is 'correct'/traditional for something like this?
In the code I was writing, I used elicitSlot a lot, which is nice because it lets me listen solely for the things I expect to hear (eg answerType "A", "B", "C"). But elicitSlot leads to you re-triggering the same intent. So would it be a matter of having each intent check if a slot is filled, and if not, speak a question and elicit that slot, and if so, set a session attribute and then forward to a different intent?
That seems sloppy. Maybe the solution is to define an askingRulesState, askingCategoryState, askingQuestionState, etc, each with only a single handler. But states with only a single handler seems... wrong?
If I'm going to ask the user a question like "What category would you like to play?", does that mean I need to create a SetCategoryIntent? And if so, how would I prevent the user from triggering that intent except when I want them to?
I realise this is a bit of a big vague question but it's really difficult for me to boil it down to something smaller and clearer, since my issue is that the flow in general is really disorienting to me. I'd appreciate even the smallest tip!
You might have a look here, this will handle a lot of the if else's and elicit slots you wrote. For the questions and such you wil indeed probably have to make a state so you can check if you are in question asking state or just in the set-up state. This will help your skill deter men what it has to do. (don't forget to ALWAYS put this state back in because Alexa is tricky if you do not do this sometimes. You can find more info over here. This also looks like a pretty good example of what you are trying to make.
Hope this helps you forward a bit.

Implementation of Gale-Shapley algorithm for allignment of ontologies

Okay here is my problem. I have to implement the Gale-Shapley algorithm for the alignment of two ontologies. I read the first 200 pages of the book "Ontology Matching" by Jerome Euzenat and Pavel Shvaiko and now I understand some of the basics of ontology matching but the problem is that the more I read the more confused I become. I really think that the problem is relatively easy but I really can't get around it and I am not getting clear instructions from my professor as they insist that I should decide everything on my own. The problem is that I don't understand the whole process. I understand the Stable Marriage Problem, I understand the basics of ontology matching but I can't seem to "connect" everything. If somebody could explain to me how the whole thing should look and how to start (the basics of a Design Document) I will be incredibly grateful.

Building a NetHack bot: is Bayesian Analysis a good strategy?

A friend of mine is beginning to build a NetHack bot (a bot that plays the Roguelike game: NetHack). There is a very good working bot for the similar game Angband, but it works partially because of the ease in going back to the town and always being able to scum low levels to gain items.
In NetHack, the problem is much more difficult, because the game rewards ballsy experimentation and is built basically as 1,000 edge cases.
Recently I suggested using some kind of naive bayesian analysis, in very much the same way spam is created.
Basically the bot would at first build a corpus, by trying every possible action with every item or creature it finds and storing that information with, for instance, how close to a death, injury of negative effect it was. Over time it seems like you could generate a reasonably playable model.
Can anyone point us in the right direction of what a good start would be? Am I barking up the wrong tree or misunderstanding the idea of bayesian analysis?
Edit: My friend put up a github repo of his NetHack patch that allows python bindings. It's still in a pretty primitive state but if anyone's interested...
Although Bayesian analysis encompasses much more, the Naive Bayes algorithm well known from spam filters is based on one very fundamental assumption: all variables are essentially independent of each other. So for instance, in spam filtering each word is usually treated as a variable so this means assuming that if the email contains the word 'viagra', that knowledge does affect the probability that it will also contain the word 'medicine' (or 'foo' or 'spam' or anything else). The interesting thing is that this assumption is quite obviously false when it comes to natural language but still manages to produce reasonable results.
Now one way people sometimes get around the independence assumption is to define variables that are technically combinations of things (like searching for the token 'buy viagra'). That can work if you know specific cases to look for but in general, in a game environment, it means that you can't generally remember anything. So each time you have to move, perform an action, etc, its completely independent of anything else you've done so far. I would say for even the simplest games, this is a very inefficient way to go about learning the game.
I would suggest looking into using q-learning instead. Most of the examples you'll find are usually just simple games anyway (like learning to navigate a map while avoiding walls, traps, monsters, etc). Reinforcement learning is a type of online unsupervised learning that does really well in situations that can be modeled as an agent interacting with an environment, like a game (or robots). It does this trying to figure out what the optimal action is at each state in the environment (where each state can include as many variables as needed, much more than just 'where am i'). The trick then is maintain just enough state that helps the bot make good decisions without having a distinct point in your state 'space' for every possible combination of previous actions.
To put that in more concrete terms, if you were to build a chess bot you would probably have trouble if you tried to create a decision policy that made decisions based on all previous moves since the set of all possible combinations of chess moves grows really quickly. Even a simpler model of where every piece is on the board is still a very large state space so you have to find a way to simplify what you keep track of. But notice that you do get to keep track of some state so that your bot doesn't just keep trying to make a left term into a wall over and over again.
The wikipedia article is pretty jargon heavy but this tutorial does a much better job translating the concepts into real world examples.
The one catch is that you do need to be able to define rewards to provide as the positive 'reinforcement'. That is you need to be able to define the states that the bot is trying to get to, otherwise it will just continue forever.
There is precedent: the monstrous rog-o-matic program succeeded in playing rogue and even returned with the amulet of Yendor a few times. Unfortunately, rogue was only released an a binary, not source, so it has died (unless you can set up a 4.3BSD system on a MicroVAX), leaving rog-o-matic unable to play any of the clones. It just hangs cos they're not close enough emulations.
However, rog-o-matic is, I think, my favourite program of all time, not only because of what it achieved but because of the readability of the code and the comprehensible intelligence of its algorithms. It used "genetic inheritance": a new player would inherit a combination of preferences from a previous pair of successful players, with some random offset, then be pitted against the machine. More successful preferences would migrate up in the gene pool and less successful ones down.
The source can be hard to find these days, but searching "rogomatic" will set you on the path.
I doubt bayesian analysis will get you far because most of NetHack is highly contextual. There are very few actions which are always a bad idea; most are also life-savers in the "right" situation (an extreme example is eating a cockatrice: that's bad, unless you are starving and currently polymorphed into a stone-resistant monster, in which case eating the cockatrice is the right thing to do). Some of those "almost bad" actions are required to win the game (e.g. coming up the stairs on level 1, or deliberately falling in traps to reach Gehennom).
What you could try would be trying to do it at the "meta" level. Design the bot as choosing randomly among a variety of "elementary behaviors". Then try to measure how these bots fare. Then extract the combinations of behaviors which seem to promote survival; bayesian analysis could do that among a wide corpus of games along with their "success level". For instance, if there are behaviors "pick up daggers" and "avoid engaging monsters in melee", I would assume that analysis would show that those two behaviors fit well together: bots which pick daggers up without using them, and bots which try to throw missiles at monsters without gathering such missiles, will probably fare worse.
This somehow mimics what learning gamers often ask for in rec.games.roguelike.nethack. Most questions are similar to: "should I drink unknown potions to identify them ?" or "what level should be my character before going that deep in the dungeon ?". Answers to those questions heavily depend on what else the player is doing, and there is no good absolute answer.
A difficult point here is how to measure the success at survival. If you simply try to maximize the time spent before dying, then you will favor bots which never leave the first levels; those may live long but will never win the game. If you measure success by how deep the character goes before dying then the best bots will be archeologists (who start with a pick-axe) in a digging frenzy.
Apparently there are a good number of Nethack bots out there. Check out this listing:
In nethack unknown actions usually have a boolean effect -- either you gain or you loose. Bayesian networks base around "fuzzy logic" values -- an action may give a gain with a given probability. Hence, you don't need a bayesian network, just a list of "discovered effects" and wether they are good or bad.
No need to eat the Cockatrice again, is there?
All in all it depends how much "knowledge" you want to give the bot as starters. Do you want him to learn everything "the hard way", or will you feed him spoilers 'till he's stuffed?

Modelling C applications

I would like to know if there are any tools that can help me model C applications i.e. Functional programming.
E.g. I'm currently building a shared library.
But to communicate my design visually, I need something like UML. I would like to do this so that the person reviewing my design need not read through 100s of pages of functions, variables and so on.
I have read about UML for C, which I'm considering.
If there is anything better out there, please let me know.
The bottom line is to visualize the design of C applications and modules without reading through 100s of pages of text, because it takes time and is difficult for the reviewers.
Any help in this area from the experts here would be much appreciated.
Thanks.
A well written text documentation brings you a far. Much further than any UML diagram could ever achieve.
You should split this in two parts:
What do you want to say?
What's the best way to saying it?
Whatever formalism you use to answer the second part, you should be sure it's not ambigous.
The good of UML is that a lot of semantic is already defined by the language so you don't have to include a definition of what those boxes, lines and arrows mean in a collaboration diagram.
But most importantly, documenting something means create a path for others to understand the subject you are documenting. A very precise description that offers no clue on how to read it is as good as none. So, use UML, Finite state machines, ER diagrams, plain English, whatever you want but be sure to include a logical path that your "readers" can follow to understand what's going on.
I had a friend that was a fan of "preciseness at all cost" and it would ask us to go through all the details before some sort of meaning would emerge.
I once ask him to do this experiment: on his next trip to an unknown city, he would have to carry the most precise map he could get. Much better, he would have to carry a 1:1 map of the city with every single detail exactly reported in scale. That way he couldn't get lost!
He declined but I would love to see him trying to use that map. Just even folding it! :)
Whatever you like. It's not a standard but many devs use it and understand it. If it does help you to communicate with other people and document your work -> its for you. If it just takes too much time and you think it's not effective, drop it. Also, don't bother with all details, as long as it resembles UML and your team can work with it, it's fine.
It's meant to help you, not waste you time.

How to type faster [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I've typed around 75wpm for the last few years but I've always wondered how people type +100wpm.
I've searched but I primarily find typing tutors that teach you to type.. not teach you to type faster. So far the only tip I've come across is to learn dvorak.
Are there exercises or tips to help break through the 75wpm wall?
I'm assuming Steve Yegge's recent post prompted this? The comments contain a number of tools and games for measurement and improvement, both online and off. I'll list them here:
Gnu Typist
TyperA
TypeRacer (Several people named this site)
Typespeed
typeonline.co.uk
Update: I just tried GNU Typist as per Mark Biek's suggestion, and I have to say that it seems like the best of the lot mentioned so far. It looks like there is a Windows version available, although I'm sure there are prettier (and more expensive) apps out there.
Setting yourself up in an ergonomic typing position is a good start. Take a look at the diagram here - notice the arms in a straight line, feet on the floor, etc.
In my experience most people tend to slow down when they get to unusual keys - numbers, symbols, punctuation, etc, so maybe some focused practice on those key combinations? practice typing out long strings of numbers and symbols, maybe try to use some Perl code as your copy-page :)
One of the things that helped me was something I learned from pianist... when doing a touch typing program, deliberately slow down and speed up your rate of typing from disgustingly slow to really fast in slow waves. This helps train yourself to figure out how to get your fingers to work together faster and reinforces the key locations.
Another one is perhaps a speed reading course might help? Generally your fingers are the last line of slow down in typing.
If you want to practice while having a little fun check out http://typeracer.com
It let's you compete against other people and trust me, there's nothing better to get you typing faster than normal than a little healthy competition.
Practice!
GNU Typist is a great, free, multi-platform program for practicing. They have different sets of exercises for practicing touch-typing as well as general Speed Drills.
Like a previous poster said, practice, practice, practice. But, if you are a developer (since you are on this site I assume that you are), then writing code will probably not be the type of practice that you need to improve your typing skills past your current maximum. I would even argue that 75wpm is more than adequate for any code writing task. But if you really want to practice more then I would recommend picking up a copy of Typing of the Dead
Consider switching to a keyboard layout that's designed for quick typing instead of just being layed out as it is for historical reasons, e.g. Dvorak or Colemak.
For me, it also helped a lot to use the caps lock key as backspace, for example using SharpKeys on Windows.
If you are really hardcore, create your own keyboard layout. On Windows, you can do that with the Microsoft Keyboard Layout Creator.
Chat. A lot.
I never received any touch-typing training. Infact, when i first started, i had to search the keyboard for the key... Now after 7 years of IMing, its all muscle memory. I have never tried to speed my typing, but a lot of times it just flows without me even realizing that i am typing as i think. Also i have noticed i can type in my usernames and phrases i often use a LOT faster than the other things.
This may or may not have been a useful answer.
Be careful, increasing your typing speed can increase the risk of carpal tunnel syndrome:
"The typing speed may affect risk, in some cases, however. For example, the fingers of typists whose speed is 60 words per minute exert up to 25 tons of pressure each day." [source]
Consistency and practice. Four things that improved my typing dramatically:
Find a comfortable keyboard that
fits your hands very well. It's less
about ergonomics or split keyboards,
but more about finding one with perfect finger reach. And this means using the keyboard for a couple weeks to see if it fits. Once you pick a keyboard, use it 100% of time. Have the same keyboard at home and work.
Make sure your workstation is
properly fitted to you. Basically, follow any decent ergonomics guide (90 degrees everywhere is WRONG!!!).
All of this "ergonomics" stuff has the benefit of stress on the rest
of your body that can distract you or cause muscle fatigue (i.e. slower typing). Again, use the same workstation configuration everywhere--if that means getting the same expensive chair at home, do it.
When emailing, chatting, and posting, use complete words and sentences. Abbreviations, slang, and other "shortcuts" taught me a lot of bad typing habits and made me lazy. They also had a lot of awkward letter combinations that didn't show up in other places, including normal composition and coding.
Consistency. Use the same tools with
the same settings and shortcuts all
the time. The less time you spend
worrying about how the software
works and reaching for the mouse,
the faster your typing will be.
You need to pick yourself up a copy of Typing of the Dead and start killing zombies. You'll be honing your typing skills and preparing for the eminent zombie apocalypse at the same time! Grab the demo to check it out!
In all seriousness, I've had this game for years and it really has helped me improve my typing skills and it's way more fun than any other typing program out there.
Type to the beat of a song. Start with a slow beat and work your way up. Don't rush it. Typing in bursts is often counter productive. Rhythm causes accuracy. The keyboard is just like a musical instrument and that's how musicians gain accuracy. You also need to practice regularly, even if just for 5 mins each day, to train your muscles.
I forget the details, but I remember the following was asked of some famous violinist:
"How did you learn to play so fast?"
His reply: "Really, really slowly".
:)
Use both hands (and all ten fingers).
To maximize your typing speed, you need to use the opposite pinky to shift/ctrl etc. and you want to minimize the amount of time you have to "reacquire" the home position. My biggest increase in typing when coding was to really learn my IDE's keyboard shortcuts, since that eliminated the relatively slow process of using the mouse.
Disable your mouse. (This is more for overall computer productivity than WPM.)
And I know you can't do it on your own, so get someone to enforce it.
It'll force you to learn keyboard shortcuts and consider keyboard-friendly options.
A nice, tactile keyboard helps. Especially if it's blank. You'll be speeding along in no time.
http://store.daskeyboard.net/prdaskeulorb.html
If you are having a problem with a particular key combo or miss-typing a particular word, or even just want to practice something, put it into your password. That way you get it fixed in your muscle memory as you can't even see what you are typing.
Practice, Practice and Practice
Make it so that you cannot see the keyboard, this will force your mind to remember where the keys are. I used this when starting on the Colemak keyboard layout and it worked really well.
The biggest way I increased my speed was by never looking down at the keyboard. I also have a very ergonomic keyboard that splits the keyboard in half so I get use to the right hand using the right side and the left hand using the left side.
My hands aren't my bottleneck, so touchtyping doesn't make me any faster. I already don't get enough bitrate out of my head to max out my hunt and peck. some people (me) may never be able to TT effectively.
agreed on muscle memory though. common thngs like usr/pass always get boshed out quickly without thinking, but for code, my hands are not the bottleneck
Get a Kinesis Essential keyboard. Keys are laid out better for faster typing.
IRC-ing a lot helpen a great deal with me;
Especially playing those Trivia like games where the fastest one gets the points.
You can also try "typespeed" on Linux.
If you really need more speed and you think you've mastered the technique you can also consider using the Dvorak keyboard layout; It will help you type fast but you really need to adapt to it.
I switched to Dvorak and my typing speed has increased, and I also learned after 8 years, how to touch type.
I would double the suggestion(s) to switch to an ergonomic typing position. Also, I've noticed that I cannot type faster on my laptop. I have an external anti-RSI QWERTY keyboard (with the reverse-V style key layout), and I can type a lot faster with more accuracy on that that I can on my laptop.
If you use a contoured keyboard, like, for instance, the Kinesis Advantage keyboard, it is easier to type blind, since it is much easier to feel where your hands are on the keyboard if it isn't flat. After a couple of days I was typing considerably faster than on a normal keyboard. And there is also a version switchable to Dvorak layout, though I never bothered to try that.
About blind typing: in my experience, knowing where your hands are is the important and difficult thing in blind typing - and after years of keyboard use you know very well where the common keys are. So just concentrating every once in a while to have your hands in the proper position for blind typing, and to type the keys with the right finger will get you into blind typing in a couple of months without any additional exercise.
(source: kinesis-ergo.com)

Resources