Short question
(maybe a bit to complex)
I have a very complex array. I need to store the "location" (in c it would be a pointer) of my last update on the array for technical reasons (see below).
How may I do that in pure JS?
Long question
(long but clear)
I am working on a kind of reinforcement learning and I have a problem with the array which I use to store what my system just learned.
Description of my array
My program is learning (or working on) the tic tac toe game. It stores what it learned on an array described below:
var learningArray = [
[/* What has been played? (Object)*/, /* What has been play following this turn? (Array)*/],
[/* What has been played? (Object)*/, /* What has been play following this turn? (Array)*/],
[/* What has been played? (Object)*/, /* What has been play following this turn? (Array)*/],
[/* What has been played? (Object)*/, /* What has been play following this turn? (Array)*/],
[/* What has been played? (Object)*/, /* What has been play following this turn? (Array)*/],
[/* What has been played? (Object)*/, /* What has been play following this turn? (Array)*/],
[/* What has been played? (Object)*/, /* What has been play following this turn? (Array)*/],
[/* What has been played? (Object)*/, /* What has been play following this turn? (Array)*/],
[/* What has been played? (Object)*/, /* What has been play following this turn? (Array)*/]
];
The array is composed of smaller arrays. Each smaller array is composed of two elements:
- The description of the turn (what has been played and where);
- The following turns using the same structures (two elements, the first stores the data and the second the others turn of play during the game).
I update my array following each turn. So normally, it stores every turn on the game. After several games, it may store every possibility of each turn of the game (next I would compute the probability of winning).
NOTE: of course, my array first has nine elements because there are nine squares on the game grid of the tic tac toe game.
The problem
Suppose I have just updated an element of my array. I need to store the location of this element to write the following turn at the next update.
I love c++ and c because pointers are pretty useful and simple to use. The solution to this problem in c is to define a pointer to the last element updated. Easy and simple.
However, JS does not support pointers (or everything is done to think it). No solution here...
How may I resolve my problem?
Tell me if you have some questions or comments