Nerdle source code

Share your advanced PureBasic knowledge/code with the community.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Nerdle source code

Post by netmaestro »

Here is the source code for Nerdle. It's quite rough and I'm a sloppy coder anyway, keep that in mind. But it does work. You need three files, here they are zipped:

https://lloydsplace.com/nerdle/nerdle_a5.zip

I had to post it this way because it's way to many characters for the forum.
Last edited by netmaestro on Sat Sep 24, 2022 8:12 am, edited 1 time in total.
BERESHEIT
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Nerdle source code

Post by idle »

Thanks for that, doesn't look rough to me.
I had a steak of 60 early on but with the change to the nytimes the best I've got was 40 and the last couple of weeks I've lost two games due to American spelling.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Nerdle source code

Post by netmaestro »

The biggest worry is words when you've got 3 or 4 letters in the right place and there's 5 possibilities - and you've only got 3 more lines. Death ensues. For me usually, anyway. Luck is important. I got beat by the same word my wife got on the second row once. Ouch!
BERESHEIT
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Nerdle source code

Post by idle »

netmaestro wrote: Thu Sep 22, 2022 5:07 am The biggest worry is words when you've got 3 or 4 letters in the right place and there's 5 possibilities - and you've only got 3 more lines. Death ensues. For me usually, anyway. Luck is important. I got beat by the same word my wife got on the second row once. Ouch!
I almost got it in two this morning, 4 in right place and then it dragged on to the 4th guess, yes there's certainly an element of luck. It's a good game with the morning coffee.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Nerdle source code

Post by netmaestro »

The Wordle game restricts you to 1 play every 24 hours, which is one reason I made this. With over 3100 words in it you can play it whenever you like for as long as you like.
BERESHEIT
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Nerdle source code

Post by idle »

netmaestro wrote: Thu Sep 22, 2022 5:26 am The Wordle game restricts you to 1 play every 24 hours, which is one reason I made this. With over 3100 words in it you can play it whenever you like for as long as you like.
3100 words isn't a lot, I would soon learn them and ace the online game. I will have a play in a couple of days, I just stuffed ~800,000 urls into a 814kb data section. Now my exe is bloated at 1,711 kb blooming heck!
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Nerdle source code

Post by jack »

thank you netmaestro :D
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Nerdle source code

Post by netmaestro »

I forgot to mention one important item: The program has threads and it must be compiled with Threadsafe on. I added a CompilerIf block to the code and that should suffice now but if you ran it before and didn't know it needed Threadsafe you could have encountered problems because the code employs a callback for the window and it would clash with the threads.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Nerdle source code

Post by netmaestro »

I fixed a couple of bugs I found in the code after what I hope was exhaustive testing. Ha, we'll see about that one. I've updated nerdle.pb so if you have it you should get the latest. It identifies itself as 'Alpha 4' at the top of the code.
BERESHEIT
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Nerdle source code

Post by ChrisR »

I am not a very good player but it is very nice.
A game would be to develop now a cheat code to find the hidden word as quickly as possible, following the letters previously found, in the right place or wrong place and optionally with a weight for the letters. And thus play against the machine.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Nerdle source code

Post by netmaestro »

I've moved to Alpha 5 now. Link in the top post is updated, everything is in one zip file, exe too as it's compiled for x64 and Windows Defender likes it now.

Changes:
1. Reworked the layout to be more inutitive. I was never happy with the return key on the left side.
2. Added some words that should've been in the wordlist but weren't.
3. Cleaned up some sloppy coding.

I have the stats page to do yet, I'm considering doing away with the .ini file and putting everything in a sqlite database.

Any bugs you find in this, please let me know.

Happy nerdling!
BERESHEIT
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Nerdle source code

Post by idle »

I agree with the key swap. I've made a few entries by mistake due ro the enter key being on the wrong side
Mesa
Enthusiast
Enthusiast
Posts: 345
Joined: Fri Feb 24, 2012 10:19 am

Re: Nerdle source code

Post by Mesa »

If u don't want cry like a little girl... U can cheat...

Code: Select all

If FileSize("nerdle_wordlist_a5.pbi") < 0
	MessageRequester("Attention", "nerdle_wordlist_a5.pbi not found !", #PB_MessageRequester_Info)
	End
EndIf


XIncludeFile "nerdle_wordlist_a5.pbi"
; Debug words(1)
; Debug BSearch("CIVET")

Enumeration
	#string
	#solution
	#button
	#string_not_in
EndEnumeration

Global Dim Words2.s(ArraySize(words()))
CopyArray(words(),Words2())

Procedure Go()
	
	search$=""
	string$=GetGadgetText(#string)
	SetGadgetData(#string,Len(string$))
	
	If string$ = "*"
		For j=0 To ArraySize(words2())
			AddGadgetItem(#solution, -1, words2(j))
		Next j
		ProcedureReturn 1
	EndIf
	
	For i=1 To Len(string$)
		ClearGadgetItems(#solution)
		search$=Mid(string$, i, 1)
		
		For j=0 To ArraySize(words2())
			If FindString(words2(j),search$,1,#PB_String_NoCase) 
				AddGadgetItem(#solution, -1, words2(j))
			EndIf
		Next j
		
		ReDim words2(CountGadgetItems(#solution))
		For k=0 To CountGadgetItems(#solution)
			words2(k)=GetGadgetItemText(#solution,k)
		Next k
		
	Next i
	
EndProcedure

Procedure reset()
	ReDim words2(ArraySize(words()))
	CopyArray(words(),Words2())
	ClearGadgetItems(#solution)
	
EndProcedure

Procedure Go_Out()
	search$=""
	string$=GetGadgetText(#string_not_in)
	SetGadgetData(#string_not_in,Len(string$))
	
	For i=1 To Len(string$)
		ClearGadgetItems(#solution)
		search$=Mid(string$, i, 1)
		
		For j=0 To ArraySize(words2())
			If FindString(words2(j),search$,1,#PB_String_NoCase) 
			Else
				AddGadgetItem(#solution, -1, words2(j))
			EndIf
		Next j
		
		ReDim words2(CountGadgetItems(#solution))
		For k=0 To CountGadgetItems(#solution)
			words2(k)=GetGadgetItemText(#solution,k)
		Next k
		
	Next i
EndProcedure


If OpenWindow(0, 0, 0, 300, 600, "Enter characters and, Cheat...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	
	StringGadget(#string, 10, 10, 200, 30, "")
	GadgetToolTip(#string, "Letters inside")
	
	StringGadget(#string_not_in, 10, 50, 200, 30, "")
	GadgetToolTip(#string_not_in, "Letters  not inside")
	
	EditorGadget(#solution,10,90, 200,540)
	ButtonGadget(#button,230,10,60,30,"Reset")
	
	
	
	
	Repeat
		Event = WaitWindowEvent()
		
		Select Event
				
			Case #PB_Event_Gadget
				Select EventGadget()
					Case #string
						If EventType() = #PB_EventType_Change 
							If Len(GetGadgetText(#string)) < GetGadgetData(#string)
								reset()
								go()
								Go_Out()
							EndIf
							go()
						EndIf
						
					Case #string_not_in
						If EventType() = #PB_EventType_Change 
							If Len(GetGadgetText(#string_not_in)) < GetGadgetData(#string_not_in)
								reset()
								go()
								Go_Out()
							EndIf
							Go_Out()
						EndIf
						
					Case #button
						SetGadgetText(#string, "")
						SetGadgetText(#string_not_in,"")
						reset()
				EndSelect
				
		EndSelect
	Until Event = #PB_Event_CloseWindow
EndIf

M.
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Nerdle source code

Post by ChrisR »

To follow up on Mesa Cheat code and as I don't want to cry like a little girl with my poor English.
I made my cheat code too, integrated in nerdle source code. Sorry to spoil this nice code, I put "; Added Cheat" tags in addition to Nerdle_Cheat.pbi.
It is based on a word list that shrinks according to the letters in the right or wrong place or not in the word.

Use F1 to suggest a word that meets the conditions of the previous lines.
With F1, Enter, F1, Enter... the hidden word is usually found in 3 to 6 tries. But sometimes 6 tries are not enough.

nerdle_a5_cheat.zip
Post Reply