Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
I'm working on a remake of my Worm game, that allows a player to play against the computer. So far, it's just the algorithm for a basic unintelligent response from the computer.
It recognizes a "word" that's being constructed, finds a word that contains that group of letters, and adds a letter to either the beginning or end of that group.
More later.
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
01-31-2023, 02:52 AM
(This post was last modified: 01-31-2023, 02:55 AM by PhilOfPerth.)
I have an algorithm that lets the computer play against itself, to semi-randomly build on a word, towards a legitimate word. It's very basic at present (with lots of GoTo's etc), but this will improve, I hope. Later it will be a human v computer version of Worm. Here's the code: (Note: it needs the WordLists files)
Code: (Select All) 'Comp v Comp Worm
Screen 12
_FullScreen
Randomize Timer
Common Shared wrd$, firstfile$, srchfile$, start$, dictwrd$
' wrd$ is the word being built, firstlist is the reference file search for start of search, srchlist is actual list being searched, start$ is the list's location
'dictwrd$ is word input from wordlist, po is position of wrd$ in dictwrd$
Seed:
wrd$ = Chr$(Int(Rnd * 26) + 65)
Locate 10, 25: Print "Start-letter: ";: Print wrd$ ' We have the first letter
StartNewWrdSearch:
firstlist = Int(Rnd * 26) + 65 ' firstlist is refence point for first wordlist to be searched, so that we know when all have been searched
srchlist = firstlist
FindAWord:
srchlist = srchlist + 1: If srchlist > 90 Then srchlist = 65 ' srchlist is ascii of list about to be searched
NextList: ' point to return to after each list has been searched
start$ = "WordLists/" + Chr$(srchlist) ' formulate path to srchlist as "WordLists/A" etc.
Locate 12, 18: Print "List being searched: "; start$
Open start$ For Input As #1 ' open the selected wordlist
DictLoop:
If Not EOF(1) Then
Input #1, dictwrd$
If dictwrd$ = wrd$ Then ' only used when dictwrd$ matches wrd$
Matched
End If
Else
Close #1
GoTo FindAWord
End If
po = InStr(dictwrd$, wrd$) ' look for wrd$ in dictwrd$
If po = 0 Then GoTo DictLoop ' if not found, get next dictwrd$
If po = 1 Then ' if wrd$ is at start of dictwrd$,
wrd$ = wrd$ + Mid$(dictwrd$, po + Len(wrd$), 1) ' add the letter after wrd$ to wrd$
Else
wrd$ = Mid$(dictwrd$, po - 1, 1) + wrd$ ' but if not at start, add the letter before wrd$ to wrd$
End If
Locate 16, 36: Print Space$(20)
Locate 16, 24: Print "Search-string: "; wrd$
Locate 14, 24: Print Space$(30)
Locate 14, 24: Print "Wordlist word: "; dictwrd$
_Delay .2
GoTo DictLoop
Sub Matched
Locate 20, 30: Print wrd$; " Matched "; dictwrd$: Sleep
End Sub
'Comp v Comp Worm
Screen 12
_FullScreen
Randomize Timer
Common Shared wrd$, firstfile$, srchfile$, start$, dictwrd$
' wrd$ is the word being built, firstlist is the reference file search for start of search, srchlist is actual list being searched, start$ is the list's location
'dictwrd$ is word input from wordlist, po is position of wrd$ in dictwrd$
Seed:
wrd$ = Chr$(Int(Rnd * 26) + 65)
Locate 10, 25: Print "Start-letter: ";: Print wrd$ ' We have the first letter
StartNewWrdSearch:
firstlist = Int(Rnd * 26) + 65 ' firstlist is refence point for first wordlist to be searched, so that we know when all have been searched
srchlist = firstlist
FindAWord:
srchlist = srchlist + 1: If srchlist > 90 Then srchlist = 65 ' srchlist is ascii of list about to be searched
NextList: ' point to return to after each list has been searched
start$ = "WordLists/" + Chr$(srchlist) ' formulate path to srchlist as "WordLists/A" etc.
Locate 12, 18: Print "List being searched: "; start$
Open start$ For Input As #1 ' open the selected wordlist
DictLoop:
If Not EOF(1) Then
Input #1, dictwrd$
If dictwrd$ = wrd$ Then ' only used when dictwrd$ matches wrd$
Matched
End If
Else
Close #1
GoTo FindAWord
End If
po = InStr(dictwrd$, wrd$) ' look for wrd$ in dictwrd$
If po = 0 Then GoTo DictLoop ' if not found, get next dictwrd$
If po = 1 Then ' if wrd$ is at start of dictwrd$,
wrd$ = wrd$ + Mid$(dictwrd$, po + Len(wrd$), 1) ' add the letter after wrd$ to wrd$
Else
wrd$ = Mid$(dictwrd$, po - 1, 1) + wrd$ ' but if not at start, add the letter before wrd$ to wrd$
End If
Locate 16, 36: Print Space$(20)
Locate 16, 24: Print "Search-string: "; wrd$
Locate 14, 24: Print Space$(30)
Locate 14, 24: Print "Wordlist word: "; dictwrd$
_Delay .2
GoTo DictLoop
Sub Matched
Locate 20, 30: Print wrd$; " Matched "; dictwrd$: Sleep
End Sub
Posts: 3,964
Threads: 176
Joined: Apr 2022
Reputation:
219
01-31-2023, 03:47 PM
(This post was last modified: 01-31-2023, 03:49 PM by bplus.)
Some very obscure words being built here. Not sure I want to play against computer
The threat of AI! overwhelming superiority to lookup things.
As an alternate goal to teach words and spelling, will need a dictionary included.
b = b + ...
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
(01-31-2023, 03:47 PM)bplus Wrote: Some very obscure words being built here. Not sure I want to play against computer
The threat of AI! overwhelming superiority to lookup things.
As an alternate goal to teach words and spelling, will need a dictionary included.
Yes, some pretty strange ones in there; I may end up weeding the word lists, and limiting it to words of 12 letters or so as well.
Not many of us have a vocab of 250,000-plus words! I've got about 50, and I just make up the rest
I could probably include a Meanings function then, too - it's pretty huge for the full set.
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
Second thoughts:
I'll leave the Words Lists intact, so those who happen to have a longer word, e.g. "CONGLOMERATIONS", can use it and have it recognized.
But I'll let the player choose a level (or have progressive levels), which will reflect the length of words presented by the computer.
|