Last change
on this file since 50 was 1, checked in by Wouter Pasman, 6 years ago |
Initial import : Genius 9.0.0
|
File size:
816 bytes
|
Rev | Line | |
---|
[1] | 1 | package agents.nastyagent;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
| 4 | import java.util.List;
|
---|
| 5 |
|
---|
| 6 | import genius.core.actions.Action;
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * Deliberately goes out of memory while choosing an action.
|
---|
| 10 | *
|
---|
| 11 | * @author W.Pasman 25jan16
|
---|
| 12 | *
|
---|
| 13 | */
|
---|
| 14 | public class OutOfMem extends NastyAgent {
|
---|
| 15 | private ArrayList<String> memory = new ArrayList<String>();
|
---|
| 16 | private final static String block = "01234567890123456789123456789012";
|
---|
| 17 |
|
---|
| 18 | @Override
|
---|
| 19 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
| 20 | doubleMemory();
|
---|
| 21 | return super.chooseAction(possibleActions);
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | /**
|
---|
| 25 | * Double the amount of used memory (starts with 32 bytes if no mem in use
|
---|
| 26 | * yet)
|
---|
| 27 | */
|
---|
| 28 | private void doubleMemory() {
|
---|
| 29 | long toAdd = memory.size();
|
---|
| 30 | if (toAdd == 0) {
|
---|
| 31 | toAdd = 1;
|
---|
| 32 | }
|
---|
| 33 | for (long i = 0; i < toAdd; i++) {
|
---|
| 34 | memory.add(block);
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.