Intuitive AI

Search…

Understanding Simulator

A simulator is developed to create an environment where intuitive decisions can be made. This section covers all the rules and basics of how the stimulator works.

The How

At the very beginning of this research, I knew that we'll need some sort of a simulator where we can test our AI's intuitive decisions (if it ever gets developed) so it was not a discovery or realization in between and that is why from start I was looking at other simulations that have been used in the study of AI.

In search of simulator

Upon researching the AI learning how to play different games like chess, go, etc, there was not a single game that could be used for this study to its full extent. I went through AlphaGo, MuZero, and a bunch of others. Though mastering the game of go which has many possibilities was amazing but at the same time, it does not satisfy the principles of intuition.

Intuition has more to do with the psychology of mind so I knew that I had to define certain principles of psychology to the simulator like what makes a human takes an intuitive decision? It's the past experience and the present moment and the thought of what will happen in the future. It should be a** **simulation where every action is inspired by a psychological principle of the real world that is known to humankind. **Basically, the idea was to reduce certainty as much as possible.**

Some of the psychological principles or real-life scenarios that were considered are:

- Humans have free will. Intuition is heavily dependent on free will, as these decisions are on spot and it is up to the person and if the person chooses to go with it or not is also on to the person.
- The randomness of life scenarios. We all live on the same planet yet for every one of us there is a different world that we live in and we make decisions based on that view of the world but certain studies also tell us that we take intuitive decisions mostly in a situation that we’re not familiar with.
- Everyone sees more failures in life than success even though if the success might be bigger than all the failures combined but we're talking about numbers here.
- We all have at certain points of our lives people who are guiding us or providing feedback about something we have asked them but the decision at end of every discussion is again in our own hands whether we decide to go with the suggestion or the other way around.
- Sometimes in our life, we have secondary goals. If we decide to pursue them they are rewarding but if we skip them there is no harm. With intuition, this factor is pretty heavy as we have to choose among different thoughts and we go with one of it and not selecting others usually doesn't have any harm but maybe another option that we skipped will be more rewarding than the one we have selected but we are happy because we have achieved the goal we were after.

After looking at certain examples of games and simulations used in AI, I decided to go with Wumpus World. Wumpus World, which was a simple world example to illustrate the worth of a knowledge-based agent to represent knowledge representation in the early ages of artificial intelligence. But the concept of the Wumpus world is not suitable for an intuitive-based environment so in order to develop an algorithm we have changed some rules and added some of our own rules to satisfy some real-life scenarios.

The Simulator

As the Intuitive AI stimulator is inspired by Wumpus World we wanted to generate an environment where it doesn't matter who is playing (Human or AI) both are forced to make some decisions based on intuition only. So, we changed some rules in the Wumpus Wold stimulator to fulfill our requirements.

Intuitive AI stimulator is a 4x4 grid (16 blocks). Every game has

- 4 pits (🕳️ ),
- 1 gold (💰 ), and
- 1 monster (👹 )

Every time a new game is started the grid is randomized and one box is revealed with a hint.

- Your goal is to find 👹 (Monster), doing so will give you 1 point and the game will end in a win.
- If you find 💰 (Gold) before finding the monster you'll get 1 more point, hence in a game you can get a maximum of 2 points. Finding 💰 (Gold) will not end the game, think of gold as an optional encouraged behavior.
- If you fall in 🕳️ (Pit) your score will -1 from the total score you have at the moment and the game will end in loss.
- If a box doesn't reveal any of the three i.e. ( 👹 , 💰 , 🕳️ ) above then the box will reveal a
**hint**that will tell you what is in the adjacent boxes.

Hints are of the following types:

**Breeze**💨 Indicate that there is Pit(s) in the adjacent boxes.**Smell**👃 Indicate that there is a Monster in one of the adjacent boxes.**Glitter**✨ Indicate that there is Gold in one of the adjacent boxes.**Breeze & Smell**💨 👃 Indicate that there is Monster & Pit(s) in the adjacent boxes.**Breeze & Glitter**💨 ✨ Indicate that there is Gold & Pit(s) in the adjacent boxes.**Smell & Glitter**👃 ✨ Indicate that there is Monster & Gold in the adjacent boxes.**Breeze & Glitter & Smell**💨 ✨ 👃 Indicate that there is Monster, Pit(s) & Gold in the adjacent boxes.**Nothing**❎ This indicates that there is nothing in the adjacent boxes.

Adjacent boxes are only up, down, left, right, and not diagonal. For example, the adjacent boxes to the hint below are marked with a red dot on the grid in the picture below:

You can **open any box at any given time** there is no pattern to follow just a goal (find monster) in place and hints to guide you to achieve that goal. These hints are always helpful and sometimes they'll help you reach the goal easily but sometimes they'll put you in a situation where you have to take risk.

You can follow your intuition to open any random box and ignore following the hint too, for example, the above hint which is wind 💨 is telling us that there are one or more pits in the adjacent boxes. It can be in all four or it can be in one and so on. So will you take the risk to open one of the adjacent boxes or choose to open any random box that your intuition tells you to open? All these choices are up to you!

Here are all the possible outcomes of a game:

- 1.The User falls into the pit. (Game Lost)
- 2.The User finds gold and falls into the pit. (Game Lost)
- 3.The User finds wumpus. (Game Won)
- 4.The User finds gold and wumpus. (Game Won)

Out of the 16 boxes, 10 boxes will have hits, 4 will have pits, one will be monster and one will be gold.

This basic summary of the stimulation is encouraging three types of behaviors:

- 1.Goal
- 2.Risk
- 3.Encouraged Optional Behavior (EOB)

The reason for placing this high number (4:1 for every four boxes there will be one pit) of risk, is on purpose and by design. Because in intuition the risk is involved and although intuitive decisions are mostly right there is always high risk and from one of the real-life scenarios this fulfills the one where everyone sees more failures than success.

EOB was something that came a bit late in the design but it was a perfect move. As humans, we strive for more with less risk. This option adds greediness to the world, where you’re striving towards a goal and you have full authority to take risks and win more points, but the risk is there equally, you can fall into the pit.

One game of IntuitiveAI simulator reflects one scenario of life in which a person is taking intuition-based decisions.

When a new stimulation loads it randomly shuffles the 4x4 grid so every time you’ll be getting a new environment with the same rules.

The new stimulation will open a box at a random spot which will give you a starting hint.

Now you can either take that hint and start planning where to move from there or you can open a totally random box out of the 15 remainings.

If we talk about the probability of risk of opening a box other than the adjacent boxes let’s say it’s 0.5, it’ll be the same for every box that is not an adjacent box to the opened hint box as shown in the image below. Hints tell us what is in the adjacent boxes.

The psychological principles or real-life scenarios how they fit into this simulator is as follows:

- Even though user gets a hint at the start they have a free will to open any box at any time. The hint is the knowledge we already have and the sense it gives us about the adjacent boxes is the knowledge we derive about the future from the knowledge we already have of which we have a certain certainty but there is still a risk that which one or all of them.
- Every single time use will be faced with a random grid with a random box revealed. The rules will always remain the same just like in our real world and we have to make intuitive decisions when we’re in an uncertain situation.
- There are 4 pits, which is a risk and the chance of failing is higher than the chase of finding the goal.
- Hints are the helping guides. You can either take them or make your own path. But in our lives, we have such helping hands that influence our decisions. In this case, all the hints will be telling the truth in the current version.
- If you find gold you get 1 extra point but if you don’t there is no negative penalty. So, it’s completely optional.

In our life, we face small situations almost every day. That one situation is one game of IntuitiveAI. We have free will, we can deal with that situation in any way we want but within certain rules. We all have a goal in life, that changes as well but we have goals. We all see failures more than success. There were times where we had a choice where we knew if we do this it’ll add an extra cherry on the top but if not it’ll still be fine. When a new game is started the grid is randomized so the previous knowledge you had is useless because it's a totally new world with the same rules. Using these principles the IntuitiveAI simulator is designed. To fit any situation in IntuitiveAI we have to define what is the goal, what are the risks and it needs to have an optional encouraged behavior. The scoring in the game is also built on psychological principles. You can only get -1, 0, 1, or 2 in the game. Most people will strive for 1, this portrays the 80% of the world population that is middle class. Many people if they see a good calculated chance that they'll be able to get 2 only then they'll take it where some people will go out of the way to take the risk of getting the 2. The boxes you open are either intuition-based or you know exactly what will happen when you open a box just like in a real-life decision-making process. The simulator lets you take the decision not only using your calculated side of the brain but also the creative side of the brain where intuition is.

Basic Logic of Simulator

The IntuitiveAI simulator for humans to play is built on JavaScript and can be accessed: **https://intuitive-ai.firebaseapp.com/******

Every game has an array indexed from 0...15, which is randomized on a 4x4 grid that has 4 pits, 1 gold, and 1 monster.

Example:

Consider this **EXAMPLE** of a new game. The array is randomized and the game array now is:

User will see the strings (symbols) as the

*strArr*

shows but behind the scenes the above array is:*indexArr*

was a sequence from 0 to 15 values and is then randomized to generate this particular game pattern and wherever in *indexArr*

there is:`0`

and`9`

and`5`

and`15`

there will always be a**Pit**`7`

there will always be**Gold**`11`

there will always be the**Monster**

The adjacent values are then calculated for each of the above elements and hence the hints are generated and finally a random index other than the one assigned to the elements is picked and is revealed.

Source Code

The source code is available in JavaScript and Python. Here we'll discuss the logic behind using the JavaScript version. A link to python will be available at the end.

We start by writing a new game function:

1

function newGame() {

2

//Code comig soon

3

}

Copied!

Inside the

`newGame`

function we start by initializing some variables:1

var numbers = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];

2

3

var numberStrs = ['❎', '❎', '❎', '❎', '❎', '❎', '❎', '❎', '❎', '❎', '❎', '❎', '❎', '❎', '❎', '❎'];

4

var tempArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

5

6

var didFMonster = false;

7

var didFGold = false;

8

var didFInPit = false;

9

10

var userGamePlayPattern = [];

11

var userGamePlayPatternIndex = [];

12

13

finalScore = 0;

Copied!

Our main array

`numbers`

is a size 16 array which has values from 0 to 15 in sequence. Then we have `numberStrs`

and `tempArray`

which will be used to work side by side one will provide a GUI based approach the other will hold numeric data against each GUI element (i.e. emoji).You'll understand more about what data we're storing for analysis purposes in the sub-page **Understanding DataSet**.

The next three i.e.

`didFMonster`

, `didFGold`

, and `didFInPit`

are all checking the outcome of the game that either user has won or lost the game and if the user has found gold in a single game.Finally,

`userGamePlayPattern`

stores the GUI values of how use has played the game and `userGamePlayPatternIndex`

stores from which index user moved to which index basically maps out how user played the game. In the end, we have `finalScore`

which will store the score of a game.Next, we need to write a method that'll shuffle arrays.

1

function shuffle(array) {

2

var currentIndex = array.length, temporaryValue, randomIndex;

3

4

// While there remain elements to shuffle...

5

while (0 !== currentIndex) {

6

7

// Pick a remaining element...

8

randomIndex = Math.floor(Math.random() * currentIndex);

9

currentIndex -= 1;

10

11

// And swap it with the current element.

12

temporaryValue = array[currentIndex];

13

array[currentIndex] = array[randomIndex];

14

array[randomIndex] = temporaryValue;

15

}

16

17

return array;

18

}

Copied!

The above function is written outside the

`newGame`

function and it is plain and simple shuffling each element to a random position within the grid.Now we go back to our

`newGame`

function and we overwrite `numbers`

array1

numbers = shuffle(numbers);

Copied!

Next, Using the updated grid we assign fixed indexes to their correspondent values:

1

var indexOfMonster = numbers.indexOf(11);

2

var indexOfGold = numbers.indexOf(7);

3

var indexOfPit1 = numbers.indexOf(0);

4

var indexOfPit2 = numbers.indexOf(5);

5

var indexOfPit3 = numbers.indexOf(9);

6

var indexOfPit4 = numbers.indexOf(15);

Copied!

The above code will assign the index of wherever the value 11 is shuffled to

`indexOfMonster`

and just like that, we have reserved numbers that will always be the same, meaning doesn't matter where 11 is shuffled to in the list, where ever it'll be the game will place monster there and the same goes for gold and our four pits.Now we need to find adjacent of each of these values so that we can assign hints accordingly. This is an important step as we need to calculate these values carefully so that we can place the right hint at the right place. Here is the code:

1

//Findinng Adjacents

2

3

var adjToMonster = []

4

if (indexOfMonster+4 < 16) { //number below

5

adjToMonster.push(numbers[indexOfMonster+4]);

6

}

7

if (indexOfMonster+1 < 16 && indexOfMonster%4 != 3) { //number right

8

adjToMonster.push(numbers[indexOfMonster+1]);

9

}

10

if (indexOfMonster-4 >= 0) { //number Above

11

adjToMonster.push(numbers[indexOfMonster-4]);

12

}

13

if (indexOfMonster-1 >= 0 && indexOfMonster%4 != 0) { //number left

14

adjToMonster.push(numbers[indexOfMonster-1]);

15

}

16

17

var adjToGold = []

18

if (indexOfGold+4 < 16) { //number below

19

adjToGold.push(numbers[indexOfGold+4]);

20

}

21

if (indexOfGold+1 < 16 && indexOfGold%4 != 3) { //number right

22

adjToGold.push(numbers[indexOfGold+1]);

23

}

24

if (indexOfGold-4 >= 0) { //number Above

25

adjToGold.push(numbers[indexOfGold-4]);

26

}

27

if (indexOfGold-1 >= 0 && indexOfGold%4 != 0) { //number left

28

adjToGold.push(numbers[indexOfGold-1]);

29

}

30

31

var adjToPit1 = []

32

if (indexOfPit1+4 < 16) { //number below

33

adjToPit1.push(numbers[indexOfPit1+4]);

34

}

35

if (indexOfPit1+1 < 16 && indexOfPit1%4 != 3) { //number right

36

adjToPit1.push(numbers[indexOfPit1+1]);

37

}

38

if (indexOfPit1-4 >= 0) { //number Above

39

adjToPit1.push(numbers[indexOfPit1-4]);

40

}

41

if (indexOfPit1-1 >= 0 && indexOfPit1%4 != 0) { //number left

42

adjToPit1.push(numbers[indexOfPit1-1]);

43

}

44

45

var adjToPit2 = []

46

if (indexOfPit2+4 < 16) { //number below

47

adjToPit2.push(numbers[indexOfPit2+4]);

48

}

49

if (indexOfPit2+1 < 16 && indexOfPit2%4 != 3) { //number right

50

adjToPit2.push(numbers[indexOfPit2+1]);

51

}

52

if (indexOfPit2-4 >= 0) { //number Above

53

adjToPit2.push(numbers[indexOfPit2-4]);

54

}

55

if (indexOfPit2-1 >= 0 && indexOfPit2%4 != 0) { //number left

56

adjToPit2.push(numbers[indexOfPit2-1]);

57

}

58

59

var adjToPit3 = []

60

if (indexOfPit3+4 < 16) { //number below

61

adjToPit3.push(numbers[indexOfPit3+4]);

62

}

63

if (indexOfPit3+1 < 16 && indexOfPit3%4 != 3) { //number right

64

adjToPit3.push(numbers[indexOfPit3+1]);

65

}

66

if (indexOfPit3-4 >= 0) { //number Above

67

adjToPit3.push(numbers[indexOfPit3-4]);

68

}

69

if (indexOfPit3-1 >= 0 && indexOfPit3%4 != 0) { //number left

70

adjToPit3.push(numbers[indexOfPit3-1]);

71

}

72

73

var adjToPit4 = []

74

if (indexOfPit4+4 < 16) { //number below

75

adjToPit4.push(numbers[indexOfPit4+4]);

76

}

77

if (indexOfPit4+1 < 16 && indexOfPit4%4 != 3) { //number right

78

adjToPit4.push(numbers[indexOfPit4+1]);

79

}

80

if (indexOfPit4-4 >= 0) { //number Above

81

adjToPit4.push(numbers[indexOfPit4-4]);

82

}

83

if (indexOfPit4-1 >= 0 && indexOfPit4%4 != 0) { //number left

84

adjToPit4.push(numbers[indexOfPit4-1]);

85

}

Copied!

The above code is calculating adjacents for the monster, gold, and our 4 pits.

Let's say that pit 4 is at the index 12 in the grid and the grid starts from 0 and Left-Top this makes the 12th index first block of the 4th row as shown in the image below.

The adjacent boxes to 12 are 8 (Above) and 13 (Right). So in the code, I've added the comment for each if-condition that explains the code so when the code will reach

`if (indexOfPit4+4 < 16) { //number below`

it'll add 12+4 which is equal to 16 and the condition will only run if 16 is less than 16 which is false so the number below will have nothing which is fine as with this example this is the expected outcome. The next if-condition is `if (indexOfPit4+1 < 16 && indexOfPit4%4 != 3) { //number right`

will do 12+1 less than 16 AND 12%4 is not equal to 3. Both these conditions are true as 13 is less than 16 and 0 is not equal to 3 so index 13 will be added to the `adjToPit4`

. Similarly, we check for left and above.Now that we know the adjacents we add some weight to each adjacent cell. Let's look at the code first:

1

for(var i = 0; i < adjToMonster.length; i++) {

2

let temp = numbers.indexOf(adjToMonster[i])

3

addValueToArray(temp, 10);

4

5

}

6

7

for(var i = 0; i < adjToGold.length; i++) {

8

let temp = numbers.indexOf(adjToGold[i])

9

addValueToArray(temp, 5);

10

}

11

12

for(var i = 0; i < adjToPit1.length; i++) {

13

let temp = numbers.indexOf(adjToPit1[i])

14

addValueToArray(temp, 2);

15

}

16

17

for(var i = 0; i < adjToPit2.length; i++) {

18

let temp = numbers.indexOf(adjToPit2[i])

19

addValueToArray(temp, 2);

20

}

21

22

for(var i = 0; i < adjToPit3.length; i++) {

23

let temp = numbers.indexOf(adjToPit3[i])

24

addValueToArray(temp, 2);

25

}

26

27

for(var i = 0; i < adjToPit4.length; i++) {

28

let temp = numbers.indexOf(adjToPit4[i])

29

addValueToArray(temp, 2);

30

}

Copied!

Let's again take pit 4 to understand the code. We call a function that we haven't created yet, named

`addValueToArray`

let's add that first:1

function addValueToArray(index, value) {

2

tempArray[index] = tempArray[index] + value;

3

}

Copied!

So now in the

`adjToPit4`

array we have index 8 and 13. So the for-loop will run two times. As at the start, we randomized the numbers array so we find at which index of the `numbers`

array 8 and 13 have shuffled to. We store it in a temp variable and then `addValueToArray`

adds it at the `tempArray`

exactly at the same index as `numbers`

array. As `tempArray`

was initialized with 0 so we add 2 in the case of pits and 5 in the case of gold and 10 in the case of monster. These values will help us determine which hint will show at which index in the grid. Next, we'll do that.1

for(var i = 0; i<tempArray.length; i++) {

2

switch(tempArray[i]) {

3

case 10:

4

numberStrs[i] = "👃";

5

break;

6

case 5:

7

numberStrs[i] = "✨";

8

break;

9

case 2:

10

case 4:

11

case 6:

12

case 8:

13

numberStrs[i] = "💨";

14

break;

15

case 23:

16

case 21:

17

case 19:

18

case 17:

19

numberStrs[i] = "💨✨👃";

20

break;

21

case 15:

22

numberStrs[i] = "👃✨";

23

break;

24

case 7:

25

case 9:

26

case 11:

27

case 13:

28

numberStrs[i] = "✨💨";

29

break;

30

case 18:

31

case 16:

32

case 14:

33

case 12:

34

numberStrs[i] = "👃💨";

35

break;

36

case 0:

37

numberStrs[i] = "❎";

38

break;

39

default:

40

console.log("Error# 874B3: Temp Value array value is not found. Value = " + tempArray[i]);

41

} //EO Switch

42

}//EO For-loop

Copied!

Once the

`tempArray`

is loaded with the values we made we run a for-loop on it. The case numbers are very easy to determine, as we know the weight for each pit is 2, gold is 5 and monster carries a weight of 10. So let's say a box has all three a pit, gold ad monster its value will be 2+5+10 = 17 and in the code above you can see `case 17`

is adding 💨✨👃 to the array. Let's say there were two pits, gold and monster around a box its value will be 2+2+5+10 = 19, and as you can see how the case is handled.As we're replacing numbers with emojis so we still need to replace values for our monster, gold, and pits. So after the for-loop ends we add:

1

numberStrs[indexOfMonster] = "👹";

2

numberStrs[indexOfGold] = "💰";

3

numberStrs[indexOfPit1] = "🕳️";

4

numberStrs[indexOfPit2] = "🕳️";

5

numberStrs[indexOfPit3] = "🕳️";

6

numberStrs[indexOfPit4] = "🕳️";

Copied!

Until this point, the code will create the grid exactly required by the simulator. Now to create a gameplay we need to open one box randomly, but it has to be a hint box and not the gold, monster, or a pit. So, we add this code:

1

//Radom opening of one box when game starts

2

var tempRandNum;

3

4

do {

5

tempRandNum = Math.floor(Math.random() * 16);

6

} while (tempRandNum == indexOfMonster || tempRandNum == indexOfGold || tempRandNum == indexOfPit1 || tempRandNum == indexOfPit2 || tempRandNum == indexOfPit3 || tempRandNum == indexOfPit4);

7

8

console.log(numberStrs[tempRandNum]);

9

10

userGamePlayPattern.push(numberStrs[tempRandNum]);

11

userGamePlayPatternIndex.push(tempRandNum);

Copied!

We generate a random number from 0-15 and keep doing that until we find a value that is not equal to the index of our monster, gold, and, pits. In this code, I've just printed that value to the console, but ow we have the index that'll be opened when the game start.

Using this exact logic, with HTML and buttons press code we've developed a simulator running here: https://intuitive-ai.firebaseapp.com/.

Expanding The Grid

In this section, we'll set some ground rules of if this grid of 4x4 is to be expanded then how do we go about it.

A 4x4 grid can make up to 16! = 20,922,789,888,000 (twenty trillion, nine hundred twenty-two billion, seven hundred eighty-nine million, eight hundred eighty-eight thousand) unique games.

When expanding the 4x4 grid it always has to be both the row and column. For example, expanding 4x4 gid to 5x5 is valid but 4x5 or 5x4 is invalid.

If you have added one row and one column then there should be one additional pit. For example, if the grid is now 5x5 there must be 5 pits in it whereas the gold ad monster remains the same.

The index you'll give to the new pit can be an odd number from any of the 5th-row or 5th column.

The above three rules are all there is if you want to expand the grid.

Last modified 8mo ago