tom dunigan
/
antsnbugs
stochastic simulation, predator/prey
main.cpp@0:fc1335b7b54f, 2019-12-23 (annotated)
- Committer:
- manitou
- Date:
- Mon Dec 23 18:56:56 2019 +0000
- Revision:
- 0:fc1335b7b54f
stochastic simulation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
manitou | 0:fc1335b7b54f | 1 | // predator play stochastic simulation |
manitou | 0:fc1335b7b54f | 2 | // https://github.com/Kristjan93/Ants-and-bugs |
manitou | 0:fc1335b7b54f | 3 | |
manitou | 0:fc1335b7b54f | 4 | #include "mbed.h" |
manitou | 0:fc1335b7b54f | 5 | |
manitou | 0:fc1335b7b54f | 6 | #include "World.h" |
manitou | 0:fc1335b7b54f | 7 | Serial pc(USBTX, USBRX); |
manitou | 0:fc1335b7b54f | 8 | Timer tmr; |
manitou | 0:fc1335b7b54f | 9 | #define micros tmr.read_us |
manitou | 0:fc1335b7b54f | 10 | |
manitou | 0:fc1335b7b54f | 11 | main() |
manitou | 0:fc1335b7b54f | 12 | { |
manitou | 0:fc1335b7b54f | 13 | tmr.start(); |
manitou | 0:fc1335b7b54f | 14 | |
manitou | 0:fc1335b7b54f | 15 | |
manitou | 0:fc1335b7b54f | 16 | printf("hit a key to step\n"); |
manitou | 0:fc1335b7b54f | 17 | |
manitou | 0:fc1335b7b54f | 18 | World myWorld(0); // seed analogRead(0) |
manitou | 0:fc1335b7b54f | 19 | |
manitou | 0:fc1335b7b54f | 20 | myWorld.print(); |
manitou | 0:fc1335b7b54f | 21 | // myWorld.display(); // TFT display |
manitou | 0:fc1335b7b54f | 22 | while (1) { |
manitou | 0:fc1335b7b54f | 23 | #if 1 |
manitou | 0:fc1335b7b54f | 24 | if (pc.readable() ) { |
manitou | 0:fc1335b7b54f | 25 | pc.getc(); |
manitou | 0:fc1335b7b54f | 26 | myWorld.simulateOneStep(); |
manitou | 0:fc1335b7b54f | 27 | myWorld.print(); |
manitou | 0:fc1335b7b54f | 28 | // myWorld.display(); // TFT display |
manitou | 0:fc1335b7b54f | 29 | } |
manitou | 0:fc1335b7b54f | 30 | #else |
manitou | 0:fc1335b7b54f | 31 | myWorld.simulateOneStep(); |
manitou | 0:fc1335b7b54f | 32 | myWorld.plot(); // for serialplotter |
manitou | 0:fc1335b7b54f | 33 | // myWorld.display(); // TFT display |
manitou | 0:fc1335b7b54f | 34 | wait(.3); |
manitou | 0:fc1335b7b54f | 35 | #endif |
manitou | 0:fc1335b7b54f | 36 | } |
manitou | 0:fc1335b7b54f | 37 | } |