Showing posts with label algorithm. Show all posts
Showing posts with label algorithm. Show all posts

Saturday, 29 January 2022

Humiliation

I like playing Scrabble-like games and for a time I used to play on my Samsung phone using an app called WORD. However, there an annoying two minute lapse between my making a move and the app responding. There were also intrusive advertisements and in the end I stopped playing. Having recently acquired an iPhone, I downloaded an app called WORD MASTER that responds instantly once a make a play and there are only small, unobtrusive ads at the top of the screen. There are four levels: easy, medium, hard and master.

I set the play level to master and won three games before losing one. I felt good. The problem with playing on the phone is that the battery drains because I like to ponder long and hard over the best possible move. That set me thinking about playing on my always plugged-in laptop using just a web browser. I came across a Scrabble-like game called WORD SCRAMBLE with an interface as shown in Figure 1.


Figure 1

There are five levels: one to five. I confidently set the level to 5 and began playing. Never have a suffered a more crushing defeat. The computer achieved a score of over 600 while I barely made it over 200. I adjusted the level to 4 the next time but was similarly crushed, although not quite as cruelly. See Figure 2.


Figure 2

As an exercise in diminishing the size of one's ego, this is one of the best. I think the Scrabble apps on the Google Play store and Apple's App store are careful not to crush their human opponents too devastatingly or else people would avoid using them. I'm sure an algorithm kicks in when the computer takes too much of a lead so that subsequent moves are less than optimal and the human has a chance to catch up. There are no such algorithms at work in this online game. 

Reluctantly, I set the level to 1 and this time I reigned supreme, scoring 575 against the computer's measly 231. I guess I can try level 2 next and see how I fare. What really turned the game around was the massive boost I received by using DJINN as shown in Figure 3. This close proximity of TW, TL and DW is quite different to traditional Scrabble.


Figure 3

Notice how the 15 x 15 game board in Figure 1 is different to the traditional 15 x 15 Scrabble board. See Figure 4.


Figure 4: Vintage 1948 Scrabble Board

An interesting twist on the game is explained in the following article:
New AI Scrabble mod only allows words that don’t exist

A festive game of Scrabble is a time-tested method of surviving the extended company of obnoxious family members. But losing to a crabby relative can make their company even worse.

But this year, uncle Nigel (name changed to protect identity) will face a different challenge. Thanks to a new AI version of the classic board game, his distressing knowledge of the dictionary will be of no use at all — because real words no longer count.

The BLABRECS system is the brainchild of Max Kreminski, an AI researcher and game designer. He describes his creation as “like Scrabble but worse.”

The browser-based tool is designed to run alongside a regular Scrabble game. But under the new rules, you can only play words that the AI says don’t exist — but sound as if they could.

The system checks whether a word is meaningless by running it through a Markov model trained on the ENABLE list of more than 173,000 words, which is used as a reference dictionary for numerous word games.

“It looks at the statistical patterns of letter sequences in English words and uses this information to determine how likely a sequence of letters is to be a real English word,” Kreminski explains on the BLABRECS website. “Then it rejects both real dictionary words and fake words that it deems insufficiently plausible.”

Kreminski admits that the AI sometimes accepts real words as gobbledeegook, particularly inflected forms of base words and proper nouns that Scrabble generally prohibits.

When this happens, he suggests playing by the spirit of BLABRECS — whatever that means to you:

Is the game primarily about exploring the vast ‘shadow English’ implied by the statistical distribution of letter sequences, or is it about the inherent absurdity of an external authority presuming to dictate your language to you? Either interpretation seems valid to me.

Kreminiski is also considering adding AI opponents to future versions of the system, so you wouldn’t have to interact with toxic relatives at all. Roll on Christmas 2021.

This has particular appeal to me because, while lying in bed before sleeping, I often try to think of monosyllabic rhyming words that begin with the progressive letters of the alphabet. For example, words that rhyme with "ake". I'd begin with "ache" and then progress to "bake" and "cake" before reaching "dake". A far as I know this isn't an English word but it sounds perfectly feasible and I've often thought about assigning a meaning to such a non-word. Figure 5 shows what the result of entering "dake" into BLABRECS.


Figure 5: https://mkremins.github.io/blabrecs/


The site suggests the following approach to making use of its features:
Get together your regular SCRABBLE supplies and pull up this page in a web browser. Then play SCRABBLE as normal, but before you play a word, use the "test a word..." box at the top of the page to check whether the AI will let you play it. Remember, you can only play words that the AI approves!

When you find a legal word to play, hit the "Play It" button to add this word to the lexicon. As you play, you can write in definitions for all the words you've invented in the "Meaning" textbox next to each word. The player who comes up with the best definition for a word can add half of that word's points to their SCRABBLE score at the end of the game.
What meaning might be assigned to "dake"? The Urban Dictionary comes to our aid here. The entry that gets the most up votes is as follows:
Dake 
Used to describe one interesting as hell dude.

A dake never fails, unless it's failing at failing.

A dake is always calm and collected and never loses his temper.

A dake encompasses the word "awesome", and succeeds in any venture that he takes on, overcomes any challenge in his way. 
Wow... did you see that guy? He would have been named dake, but his parents didn't want everyone to know how successful and dominating he was just by hearing it.
By ladyfalcon November 28, 2011

  The github site also explains the origin of the "word" BLABRECS:

Why is it called BLABRECS? 
I generated every possible permutation of the word SCRABBLE and asked an early version of the AI to sort them from least to most statistically likely. BRABLECS won out by a significant margin, beating not only the real word SCRABBLE but also my hand-designed previous title BESCRALB. Then I switched the L and the R because BLABRECS sounds better and I'm not about to let a computer tell me what to do.
On the subject of AI, the two most popular AIs for Scrabble are Maven and Quackle. To quote from Wikipedia:
Maven is a computer opponent for the game created by Brian Sheppard. The official Scrabble computer game in North America uses a version of Maven as its artificial intelligence and is published by Atari. Outside North America, the official Scrabble computer game is published by Ubisoft. Quackle is an open-source alternative to Maven of comparable strength, created by a five-person team led by Jason Katz-Brown. A Qt cross-platform version of Quackle is available on GitHub.
Figure 6 shows an example of a Scrabble game in progress using Quackle, an open-source program. The first few plays are JOKED 8D 50, followed by REV(O)TInG E5 94 and YEX# F4 56. The # means a word valid in games using the British-originated word list (CSW) only.


Figure 6

Saturday, 23 May 2020

Rubik's Cube

For some reason, after all these years, I decided that I would teach myself how to solve a 3 x 3 Rubik's cube which I've succeeded in doing. However, I need to practise so that the steps become automatic and so for this reason, I'm summarising the steps here. I used a YouTube video that outlined a number of algorithms to follow in order to solve the cube.



The first step is understand the notation and Figure 1 shows the four terms for the four faces that will be used in the solution (D for Down and B for Back are not used):

Figure 1

Figure 2
STEP 1: the first step is to create what is called the Daisy. See Figure 2. This is quite straight forward and doesn't require any special algorithms as will be needed later. It can be completed simply by careful inspection. 

We then rotate the bottom two layers so that one of the centre square colours matches that of a white edge. Once this has been done, the face is then rotated through 180°. 

This is repeated for the other three faces. Figure 3 shows an alignment of the green centre square with the corresponding green/while edge. The face is now ready for the 180° twist. This completes the first step where we have a white cross.

Figure 3
STEP 2: the idea in this step is to complete the white face. For this we use what is called the RIGHTY ALG where ALG stands for ALGORITHM. This algorithm involves a right face clockwise turn, an upper face clockwise turn, an anticlockwise right face turn and an anticlockwise upper face turn. This is depicted as R U R' U'

The white cross is placed face down and the corner whites are first positioned above where they need to be and the righty alg is applied repeatedly until the white corner pieces are in their correct positions. At the end of this step, the while face is now complete.

STEP 3: in this step we complete the bottom two layers. Additionally, this will involve the use of the LEFTY ALG which is characterised by L' U' L U or, in other words, a left face anticlockwise turn, an upper face anticlockwise turn, a left face clockwise turn and an upper face clockwise turn. In addition to the use of the lefty and righty alg, the cube will need to be spun clockwise or anticlockwise. See Figure 4:

Figure 4

To move an edge to the right, the steps shown in Figure 5 must be followed where R stands for the righty alg and L stands for the lefty alg:

Figure 5

To move an edge to the left, the steps shown in Figure 6 must be followed:

Figure 6

At the end of this third step, the bottom two layers should be complete.

STEP 4: this step involves creating a yellow cross, assuming one has not already been created accidentally. There are two possible scenarios that need to dealt with. The first occurs if one arm of the cross is already complete. See Figure 7 for the algorithm to complete the cross in this scenario (note that the already completed arm needs to be held horizontally as shown):

Figure 7

If neither of the two arms of the cross are complete and there is more than the central yellow square uppermost, then the algorithm show in Figure 8 can be used (note the empty corner must be in the bottom right position and care needs to be taken with lower case f which means the front two faces are rotated not just the first face):

Figure 8

Sometimes only the central yellow square is uppermost. In this case, complete the algorithm for the line: F R F'. This will produce the corner and the f R f' can then be applied.

STEP 5: this step involves getting the corner pieces of the last layer into their proper positions. Sometimes, two adjacent corners will need to be interchanged. In this case, use the algorithm described in Figure 9 (note that the corners to be swapped must be positioned on the right):

Figure 9

For a diagonal swap, the previous step needs to be completed once in any orientation (provided yellow centre is uppermost) to be produce a situation where an adjacent swap is required. Position the corners to be swapped on the right and repeat the algorithm again.

STEP 6: now that the corner pieces are correctly positioned (but in some cases twisted), we want to complete the yellow face. The first step is to flip the cube so that the white face in uppermost. See Figure 10.

Figure 10

Next, identify a corner that needs to be twisted and place it on the bottom right. See Figure 11.
Figure 11
Finally, carry out the RIGHTY ALG until the corner is correctly positioned. See Figure 12:

Figure 12

After doing this for one corner, rotate the bottom layer so that another yellow sticker that needs twisting is in the bottom right position. Keep doing this until the yellow face is completed.

STEP 7: now the edges on the last layer need to be positioned correctly. There are two possible cases to deal with. The first is when one edge is positioned correctly and the second is when no positions are positioned correctly. The first case algorithm is shown in Figure 13 (sometimes this needs to be done twice).

Figure 13

For the case where no edges are correctly positioned, carry out the above algorithm to get an edge that is correctly positioned and then repeat the algorithm with the correct edge facing forward. And that's it. These moves should lead to a completed cube.



For a mathematical examination of the Rubik's cube, the following Numberphile video is recommended viewing: