brilliant engineering ideas needed!!

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
The structure in post 117 might be nice to have, but probably not required. I think you would only need one register to store the location of a piece that has been lifted by the human, eg. if the rook moved from D5 to H5, the scan would notice that D5 is no longer present and store 0x45 in the register and maybe set a flag to say that it is waiting for it to be put down, then the scan would notice a magnet at H5, then you send the ASCII string "24585".

.....
Ok! I think I got that....just one register to store the location of any piece...then there should be a table with location value of the whole board...table of 64 entries! correct!?

time to post some code now...
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
So basically there will be a table like attached that the register stores location from....there will be an index that will be updated based on the current scanning location...

making sense!?
 

Attachments

Markd77

Joined Sep 7, 2009
2,806
Ok! I think I got that....just one register to store the location of any piece...then there should be a table with location value of the whole board...table of 64 entries! correct!?

time to post some code now...
No, just one variable to store where the piece has moved from. I'm bad at explaining things sometimes. There are many ways of doing it but I picture for the rook move I mentioned before:
Computer move completed or start of game.
Scan the board and save it in the 64 bit (8 byte) array containing the current state of the board - arr_board.
Scanning routine XORs the sensors against arr_board
Find the location that had a piece and now doesn't and convert to grid position to store in the single lifted_piece register, eg. 0x45
Don't change arr_board. Start a two second timer.

Scan the board and if there are any changes restart the two second timer.

When the timer expires and there is a piece where there was none before then the move is completed.

It's a bit like debouncing, just waiting for a period when everything has been stable for a while. Even if the human always lifts the pieces, there's a good chance of the magnet triggering a sensor other that the original and final places.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
No, just one variable to store where the piece has moved from. ......

Scan the board and save it in the 64 bit (8 byte) array containing the current state of the board - arr_board.
Scanning routine XORs the sensors against arr_board
Guess that part was discussed in post #114 and #115 whereby 8 bytes are needed for the xoring...and they all have initial values b'00000011' to indicate the presence of pieces in the first 2 rows.

Rich (BB code):
 rows_col1   ; 
 rows_col2   ; 
 rows_col3   ; 
 rows_col4   ;
 rows_col5   ; 
 rows_col6   ; 
 rows_col7   ; 
 rows_col8   ;
Find the location that had a piece and now doesn't and convert to grid position to store in the single lifted_piece register, eg. 0x45
Don't change arr_board. Start a two second timer.

Scan the board and if there are any changes restart the two second timer.

When the timer expires and there is a piece where there was none before then the move is completed.
Now when the absence of a piece is detected the appropriate value from the table is loaded to store the location of where the piece was lifted from...then after the timer you mentioned...and other value from the table will be loaded when the lifted piece will be put down...then after the message will be sent....

Is that what you mean...maybe we talking about the same think but expressing it a bit diffrently...I think I got you from the first time...lemme know if I am still wrong!

[edited] I forgot to add the 'retlw' before the numbers

thanks!
 
Last edited:

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
So there will be 2 registers, 'loc_from' and 'loc_to' to store the location the piece was lifted from and the location the piece is put down to respectively...both registers load loctions from that table...

I don't know if it make sense ...but anyways the simpler solution will be used!!
 

Markd77

Joined Sep 7, 2009
2,806
Probably about right, if you post a template of the code, just variable declarations and empty loops with brief descriptions of what they will do, no need for any actual code, then I can have a look for any issues.
Just had a thought that the PC should either send a special command for new game, or the PIC should keep an eye out for all the pieces moved back to original positions, because otherwise the PIC doesn't know.
 

Markd77

Joined Sep 7, 2009
2,806
So there will be 2 registers, 'loc_from' and 'loc_to' to store the location the piece was lifted from and the location the piece is put down to respectively...both registers load loctions from that table...

I don't know if it make sense ...but anyways the simpler solution will be used!!
Yes that sounds about right.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Now given that the sensors are active-low, what should be the initial value of PORTD (rowport)? b'00000000' or b'11111111'!?? coz a '0' read from PORTD = presence of piece...
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
With no pieces on the board it would be b'11111111'
I understand that but a bit confused tho...now what should be the initial value of rowport and the initial value of each register (8 in total) that holds the state of the pieces in each colum!? I initially said b'00000011'...but nomore sure with this active -low thang...

And for each of these 8 registers...we should check for the absence of pieces in the first 2 rows for the 8 columns!

Now question is that absence of the piece on the board is represented by what? '1' or '0'?

rowport will be xored the following registers for the 8 columns ...

for example for column 1, we gon have:

Rich (BB code):
movfw    rowport            ; read rows into W
xorwf     rows_col1,f       ; compare with old rows values
then I guess we need to check for the 8 bits of rows_col1, correct?

I am getting confused with this thang....#notgood#

Guess I am tired...need to take a break and re-read post #123 carefully....
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
I understand that but a bit confused tho...now what should be the initial value of rowport and the initial value of each register (8 in total) that holds the state of the pieces in each colum!? I initially said b'00000011'...but nomore sure with this active -low thang...

And for each of these 8 registers...we should check for the absence of pieces in the first 2 rows for the 8 columns!

Now question is that absence of the piece on the board is represented by what? '1' or '0'?

rowport will be xored the following registers for the 8 columns ...

for example for column 1, we gon have:

Rich (BB code):
movfw    rowport            ; read rows into W
xorwf     rows_col1,f       ; compare with old rows values
then I guess we need to check for the 8 bits of rows_col1, correct?

I am getting confused with this thang....#notgood#

Guess I am tired...need to take a break and re-read post #123 carefully....
At the start of the game they would be b'11111100' but what I meant by XOR was to use W as the destination and then check the Z flag to see if the port is the same as the saved state.
Say the human moves a knight to column "1" as the first move, the computer moves, then rows_col1 would then contain b'11111000' ready to detect a change.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
regarding post #123!

how long it would take to scan one column? and that 2 second timer!! why 2 seconds? is the 2 second timer the time to scan the whole board!!??
 

Markd77

Joined Sep 7, 2009
2,806
The whole board can probably be scanned 10 times a second. The two second timer is in case the human moves the piece past one sensor on the way to it's final destination, to avoid detecting a move that wasn't intended.
Reread 120 and 123 when you are less tired and hopefully it will make sense.
 
Top