Transferring a 1x25 array from one stamp to another
CP223
Posts: 5
So i have a final project I have spent weeks on, im just about done when I get an "EEPROM Full" error, so my idea is send the array that 1x25 to a second stamp. The project is create a 5x5 grid and place two ships (1x3 and 1x2) randomly, becasue Im not a coder i used a random number seed to get a number from 0-24 and a lot of if then statements to place the ships. there is an array from 0-24 indicating a spot on the grid. Each grid is initialized at 0 meaning open, then the array is changed to 1 if the ship is placed there. I want to send this to a second stamp. THE PROJECT IS DUE TOMORROW so please help!
Comments
Maybe you can make better use of the EEPROM for the 5x5. Are you using a location for each of the 25 places?
Grid(idx) = 0
NEXT
FOR idx = 0 TO 24
NEXT
' runs through random numbers until player hits begin
DO
randval=randval+1
randval2=randval2 +1
DEBUG ? Ship1
RANDOM randval
RANDOM randval2
'Ship1 VAR Byte
'Dir VAR Nib
Ship1 = randval//15
Dir = randval//2
Ship2 = randval2//21
LOOP UNTIL IN10=1
'placing ship1
IF Ship1=0 AND Dir=0 THEN
FOR idx=Ship1 TO (Ship1+2)
Grid(idx) = 1
NEXT
Grid(11)=2
Grid(10)=2
ELSEIF Ship1=1 AND Dir=0 THEN
FOR idx =Ship1 TO (Ship1+2)
Grid(idx) = 1
NEXT
Grid(16)=2
Grid(21)=2
I had a var that indicates direction called DIR if 0 its horizontal if 1 its vertices. I would have 14 possibilities for each and two orientations, therefore 28 plus the same for the 1x2 ship.
I thought that you were writing the 5x5 into the EEPROM.
You are putting it in RAM.
Store the ships in RAM as bits, don't use a whole BYTE for one position.
Here are how a couple of ships could be rendered:
But wait, there's more:
"my intention is to have each grid point equal a value 1-4"
Still, you don't need a byte for each of those.
"is EEPROM error due to not enough memory because the total, nib, byte ext amount is to high r is it a maximum number of commands you can give."
The RAM size doesn't change, it's always allocated, it's separate from the EEPROM (where the programme is kept).
EEPROM Full is telling you that your programme is too big.
The BASIC Stamp generates an ocean (a 5
There's no magic way to write this program. It's a complex problem. You have to write it and get it to work in pieces, then optimize it so it will fit in the limited space available (2K bytes for code and 26 bytes for variables). It's not something you can do like this with an all-nighter. Adding a 2nd Stamp won't help. Usually adding a 2nd microprocessor makes a problem like this more complex, not simpler. That's why this is a Difficulty 9 problem.
Using lots and lots of IF statements tends to make a program pretty large. Usually to save space, you have to program smarter, use tables where they make sense with the tables stored in EEPROM either as LOOKUP statements or using DATA and READ statements. Use subroutines where you can to eliminate duplicate decision making (and duplicate code).
I don't understand why you can't use a bit array. The smaller ship will occupy 2 adjacent cells while the larger ship will occupy 3 adjacent cells and a cell is either occupied by part of a ship or unoccupied.
SEROUT <pin>,<Baud>,["["]
FOR i = 0 to 24
SEROUT <pin>,<Baud>,[BIN1 Grid(i)]
NEXT i
SEROUT <pin>,<Baud,["]"]
and this sort of thing on the receiving end
SERIN <pin>,<Baud>,[WAIT("[")]
FOR i = 0 to 24
SERIN <pin>,<Baud>,[BIN1 Grid(i)]
NEXT i
SERIN <pin>,<Baud>,[checkChar]
IF checkChar <> "]" THEN
DEBUG "Error",CR,LF
STOP
ENDIF
<pin> is the I/O pin number that you're using and <Baud> is the Baud constant needed. Typically you'd use normal / 2400 Baud / 8 bit and the constants are given in the Stamp Reference Manual. When you connect two Stamps together like this, you usually place a resistor between the two I/O pins to prevent damage if you make a programming error. 3.3K should work.