Welcome to the Bitcave! Nerdiness, Jokes, Mods, Ideas, and coding!

@Xavion: Super Added.

@cablex17
That’s totally already the plan. I went back and listened to the livestream to be sure, but yeah, all entities are controlled by intentions and actions. They are already implementing a messaging system between entities, and so these three aspects are going to be the primary starting points. Mods that affect assets and attributes will likely be prohibited. Honestly, when laid out the way @Tom and @Ponder have laid it out, it will be super easy to verify that files haven’t been changed or injected prior to a ladder bout. The idea entails dropping a copy of one map in right next to a copy the other and flagging each group as diplomatic foes, requiring some basic “Go kill them” or “Turtle up” AI to be in place. I will provide failsafes for two “Turtle up” fortresses, negative enough that having a secondary strategy is a necessity (I’m thinking a timeout draw equates to a loss for both sides, for example.)

edit: Updated the Daily challenge, added a new modplan.

If anyone was wondering why I chose that particular challenge, it was because that was the first program I ever wrote. In BASIC, on an Apple II, in third grade. It queried, “How do you spell Halloween?”. Irony: Most kids got it wrong.

Have fun,
Bits

P.S. Thanks for consolidating my posts @SteveAdamo. I keep forgetting doubleposting is taboo.

1 Like

bah, its really just a pet peeve… :wink:

and i only try to do it if folks havent responded via individual quotes to folks… that tends to get more complicated to follow…

as for the challenge, im intrigued! :smile:

1 Like

I feel really stupid for asking this/having trouble with this, but I’ll ask anyway so I can learn. What exactly would cause the error “too long without yielding,” and what is an easy way to fix it?

I’m pretty sure it’s got something to do with being in a loop too long without a yielding statement, I don’t really remember so I suggest you check out the CC forums. For example by searching for “too long without yielding” on them you get a fairly hefty list of results and fixes for the problem.

yes, i believe xavion is correct… you likely have a loop or other iterative process that is taking an inordinate amount of time to complete… a very simple suggestion to add which will force a yield is sleep:

while true do
  if (some-iterative-test-here) then
        -- code to execute if true
  else
        sleep(10)
  end
end
1 Like

Well, thanks for making me feel better about myself :wink:

Aside from crashing my computer because I forgot to terminate half my scripts, I’ve learned a lot from attempting to code for today’s challenge, and I think looking at other people’s entries will make things make even more sense.

2 Likes

Looks over his own thread and panics…

3 Likes

@Paranundrox That would be if anyone would submit their code. XD There’s not only one way to do it, so I’m going to extend the challenge for another day, maybe two depending on response, before moving on. I’ll submit my version once we get some solid replies, though I entirely expect someone to have a better, more efficient one, and ask me questions that make me feel stupid. (I’m a hobbyist coder, so sometimes (particularly in bash scripting) I take the longer route becaue who the fuck knows how ‘awk’ works.)

@Paranundrox again, I do believe @SteveAdamo is correct. Think of the script as a conversation between the code and the interpreter (The thing that makes your code go). If the code just keeps making the longest uuuuuuuuuuuuh imaginable, the interpreter will be like, “No, go die in a fire.” It’s a safeguard to prevent infinite loops, I’d guess. Sleep() essentially says, “No really, my brain hasn’t shat the bed, I’m just waiting on shit.” and the interpreter is like, “Fine, but hurry your ass up.” Make sense?

@TobiasSabathius: Dude, your thread is so awesome I think even @SteveAdamo gives it a break.

1 Like

Not as much as you’d think. Anyway tips for other people on mac, Chrome flat won’t run Java 7 so it’s a no go, go for Safari/Firefox. You’l likely need to update before being able to use it anyway. I didn’t try Firefox and when Safari didn’t seem to be working for a bit I gave up on it and just used minecraft to run it.

I’m still working on a solution as my first attempt keeps spewing syntax errors at me even though it should work.

Also in relation to the not yielding error, it’s specifically a computer craft thing. It’s there to allow for multiple computers to run and update peripherals and the like, easiest way to fix it is to just call sleep(0) in the loop as that will yield. e.g.

while true do  
    sleep(0)  
    -- code goes here  
end
1 Like

Thanks for being my Apple (I gotta stop calling it mac) buddy! I assumed the java bit would be good enough. However, for the exercise of creating a spelling bee, the luatut interpreter would have worked as well, (I HOPE).

:smile:

Thanks again @Xavion. Also, thanks for clearing up the yield issue.

Extinct Jironisaur Hunter

-Bits

There is also Lua: demo which works fine as well, both it and luatut have disadvantages though. Luatut performs all input before any output, even in loops so my code causes it to just spam inputs without asking for words until it locks up. Lua.org blocks reading so it doesn’t work in this case either.

Now for challenge

[quote=“bitassassin, post:1, topic:1622”]Most efficient code
[/quote]
Heh
Anyway code is here, the only ways I can think of it to make it more size efficient are translating to other languages, removing/changing words, or removing functionality.

w={"Honey","Wax","Halloween","Indubitably","Stoners","ERROR:3:Out of Range"}u=string.upper p=print while 1 do c=w[math.random(1,#w)]p("Spell "..c)g=io.read()p(u(c)==u(g)and"Y"or"N")end

@Xavion lmao:

Your code Qualifies. I never would have thought to use such simple concatenation for the query! XD Great Job!

string.upper negates them using correct capitalization, but I wonder if it would make ‘;’ into ‘:’. I’m totally going to test that nao (even though that would mean 3 would become #). In the future I’ll provide wordlists and parameters (such as whether string.upper is necessary) for projects. Your entry has highlighted the necessity for that.

For example, my original code back in the day was:

10 CLS
20 PRINT "Welcome to the Spelling Challenge!"
30 INPUT "Can You spell Halloween?" a$
40 IF a$="Halloween" THEN GOTO 70
50 ELSE PRINT "I'm sorry, pay more attention in class. Please press Enter when done."
60 GOTO 80
70 PRINT "CONGRATULATIONS! You got it right! Please press Enter when done."
80 SLEEP
90 GOTO 10
100 END

So I guess in light of that the most accurate I can be in lua is:

-- Not Fancy Spelling Bee, v1
-- Variables:
i="Halloween"
-- Script:
while true do
 print( "\n \n Welcome to the Spelling Challenge!" )
 print( "Can you spell Halloween?" )
 x=io.read()
 if( x == i ) then
  print( "Congratulations! You are not a failure! \n \n" )
 else
  print( "Nevermind, I'll ask someone else, because you are obviously daft. \n \n" )
 end
end

So yeah, my script doesn’t win on efficiency at all, and I expected that. The point of this exercise (beyond getting you to think a little bit in Lua) is to introduce everyone to variables, conditionals and functions, but @Xavion also touches on functions as first-class values (meaning, in me undystandy terms that you can assign entire functions to variables and then use the variable in every place you would use the function, among other things), concatenation (stringing multiple things together to form one argument, in his case a string, string modification (in his script he changes each attempt and the answer into all uppercase letters to eliminate case as a possible cause of failure - i.e. playa and PlAyA would be compared as PLAYA and PLAYA) and assigning multiple values to arrays (and pulling things out of them (randomly even. Damn Xavion, you smartie)). Again, Great job!

Can anyone do better?

1 Like

This is my first time doing anything coding related, I actually downloaded Lua yesterday (and didn’t even open it) so I know only what I’ve learned today. I included a few pointless little tid bits to amuse myself, and it probably isn’t too incredibly well done, but here goes.

io.write ("What is your name? ")
name=io.read()
io.write ("Hello " .. name .. ", do you think you could do me a favor? ")
answer=io.read()
if answer=="no" or answer=="no " or answer=="No" or answer=="No " then
	print("Oh, okay...well I suppose I'll be going then.")
elseif answer~="no" then
	io.write ("Great! I appreciate the help. Do you think you could spell dolphin for me? ")
	dolphin=io.read()
	if dolphin~="dolphin" then
		io.write("You're not very good at this...Care to give it another shot? ")
		answer2=io.read()
		if answer2~="sure" then
			print("Your loss")
		elseif answer2=="sure" then
			io.write("Awesome! So how do you spell it? ")
			dolphin=io.read()
			if dolphin~="dolphin" then
				print("I give up.")
			elseif dolphin=="dolphin" then
				print("Oh thank you! I can never seem to remember if it's a p or a q, silly me.")
			end
		end
	elseif
		dolphin=="dolphin" then
	print("Oh thank you! I can never seem to remember if it's a p or a q, silly me.")
	end
end

It’s more of a conversation about spelling than it is a spelling bee, but I was just playing around and this is what happened, so I went with it :smile:

I’ll probably go back and add a ridiculous number of "or"s in there, to account for varied responses. But this is my first shot at coding :tongue:. Any advice? Tips or tricks from the master coders out here?

edit: I encountered an error if you refuse the first time, simplified that line (line 5) to

if answer=="no" then

so no variable answers there, but whatever=P

edit(again): I’m not even sure what’s different, might have been a user error. I have no idea, haha. But it worked when I did that, so no worries.

@cablex17: io.write() is actually more robust and appropriate than print() in most cases, as print can do unexpected things (such as newlines and string conversion) that may not be ideal for your application. io.write() also does not, print to standard output guaranteed (print() does I think) which actually makes it more likely for inclusion in final mods (writing to logs, changing item attribute files, etc.). If you take a look at @Xavion’s code and mine you can extrapolate a few things that would help, but below I’ve commented out some things I would do:

--[[ This is my personal preference. This loop makes the program restart whenever it completes. Useful sometimes to test various inputs. Also useful on computercraft to lock down the machine.--]]
while true do
	--[[ Instead of typing it twice here is the win statement in a variable. I also added a space to every echoed string for prettifying purposes.--]]
	win=" Oh Thank you! I can never seem to remember if it's a p or a q, silly me."
    io.write (" What is your name? ")
    name=io.read()
	--[[ Here I detailed to the user what the acceptable answers are.--]]
    io.write (" Hello " .. name .. ", do you think you could do me a favor? (y/n) ")
	--[[ Here I added an argument of 1 to io.read, making it so we only take the first letter (mwahahaha) Adding string.upper() forces 'n's to be 'N' limiting the possible number of replies to 26.--]]
    answer=string.upper(io.read(1))
    if answer=="N" then
    	print(" Oh, okay... Well, I suppose I'll be going then.")
	--[[ However, since this comparative is equal to 'anything other than N' we only need the two options.--]]
    elseif answer~="N" then
    	io.write (" Great! I appreciate the help. Do you think you could spell dolphin for me? ")
		--[[ Added string.upper() to cover dOlPhIn and all other variants. We care about spelling, not case. Alternatively one could use string.lower()--]]
    	dolphin=string.upper(io.read())
		--[[ Now if they get the spelling right they win.--]]
    	if dolphin~="DOLPHIN" then
		--[[ Removed awkward correct response, and added a little guide to options at the end to be verbose.--]]
    		io.write(" You're not very good at this...Care to give it another shot? (y/n)")
			--[[ Another string.upper() and arg of 1 to eliminate erroneous replies.--]]
    		answer=string.upper(io.read(1))
    		if answer~="Y" then
    			print(" Your loss. Maybe next time.")
    		elseif answer=="Y" then
    			io.write(" Awesome! So how do you spell it? ")
				--[[ One last string.upper()--]]
    			dolphin=string.upper(io.read())
    			if dolphin~="DOLPHIN" then
    				print(" I give up. You're bad at this.")
    			elseif dolphin=="DOLPHIN" then
    				print(win)
    			end
    		end
    	elseif
    		dolphin=="DOLPHIN" then
    	print(win)
    	end
    end
end

I’m working on an even more ridiculously efficient version (I have now realized how difficult it is to script at work), a version based off of @Xavion’s. I’ll release that tomorrow. In the future remember to comment vigorously! It’ll make it so much easier for people to work with you on mods and so forth, and is (to me) more important than an obscure mess of perfect efficiency.

Whoooooooo!
Bits

Wow! Thanks for that, I wasn’t expecting so much awesome, haha. I tried to do a few of those things, like the while do, and looping, but I couldn’t figure it out on my own. Many thanks for the assistance, I think I’ll go refine it right now :blush:

I would recommend trying out @Xavion’s “replacing commands with variables” angle. I wouldn’t really recommend the ‘do it all on one line’ angle unless you are the only one who will ever see the code and you know for a fact it will never be changed. Or if efficiency is so paramount that it’s actually necessary, document the code in another file, and add one comment at the beginning directing users with questions to that file.

@Xavion undoubtedly wins the efficiency contest though, so I’ll be updating the main post tonight. Words make fun do.

If I don’t do anything you didn’t it can be cut down further. Observe

w="Wax"p=print while 1 do p(w.."?")g=io.read()p(w==g and"Y"or"N")end
4 Likes

Oh mi lordie @Xavion I choked on my cocoa puffs. Fantastic job!

I just remembered! I was meaning to say it a while back but another game thing that supports lua is the T-Engine 4 and ToME 4 it’s a free open source rougelike. The engine allows for building games in lua (designed for rougelikes) and ToME is the game that was made with it. I didn’t play it for too long before getting distracted by another game but it was fun as well while I played so I suppose that’s a plus.

Also we ever going to get another challenge?

@Xavion and EVERYBODY ELSE. :wink:

Apologies for the late reply! YES! There will definitely be another challenge (And more after that!)

I’ve been super swamped at work for the last week, and I’m up for a major promotion (from Customer Support to Systems Engineer, because someone noticed that I know stuff apparently), so I have to keep dotting my 'i’s and crossing my 't’s.

I have the holiday (American Independence Day for those not in the US) off, so I will strive to get the next three challenges designed and ready to deploy then, so that I can move to a twice-weekly challenge schedule.

I will do my best to make us all experts in Lua by the time Beta is released! Just you wait!

As to the AI tech, I was studying the videos from @Ponder and @Tom and it seems as though pathfinding will be black-box native code. (This will make it run SUPERFAST compared to if it was implemented in Lua, however may present some major challenges to AI fiddling in this regard). Because of this, I’m going to see if I can lobby for (if it’s not already possible) a metered re-evaluating pathfinding system or hooks for AI updates, something like the following (warning: super rough pseudocode):

1. Unit to path from A to B
2. Unit sorts rough path in native code
3. Unit sections rough path into re-eval zones (A.1-A.10, in this example)
4. Unit checks hooks for modifying factors (ohemgee too many mobs that way / I think I'm being trapped / I'm an archer, I should be lobbing arrows at them as I retreat)
5. Unit advances to A.1
6. Repeat 4 & 5 for A.2 through A.10 until arrival at B

As some of the fancier examples of pathing systems already re-evaluate best route and continued route availability at various points in the path, it seems logical that these hooks shouldn’t be too difficult to implement, but they would be integral to AI modifications and AI automation for the AI smackdown competitions. AI AI AI. (I say that a lot for some reason.

That’s all I have for now! I’ll flesh it out more and add it to the main post tomorrow! I’ll also be adding the sweet game engine hooha you found to the main post then! I’ll be looking at in more depth and may even use it for some future challenges! (making a cheesy little arena roguelike as a community anyone?)

Again, sorry for not being more active in the last week!

BitAssassin away!

SIDE NOTE!
I can almost always be found (as ‘bits’ in the IRC channel #dc206 on EFNet (The same IRC server with the unofficial #stonehearth channel which I am also usually in) So feel free to poke me over there!