Mercurial > hg > Members > nobuyasu > Alice > DPPAlice
changeset 16:f5c2fad58b7e
add TakeRightForkCodeSegment TakeLeftForkCodeSegment
author | one |
---|---|
date | Sun, 09 Dec 2012 22:29:59 +0900 |
parents | 7e91e919a7de |
children | 92cde6277018 |
files | src/alice/test/dpp/codesegment/ScheduleCodeSegment.java src/alice/test/dpp/codesegment/TakeLeftForkCodeSegment.java src/alice/test/dpp/codesegment/TakeRightForkCodeSegment.java |
diffstat | 3 files changed, 68 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/test/dpp/codesegment/ScheduleCodeSegment.java Sun Dec 09 22:09:46 2012 +0900 +++ b/src/alice/test/dpp/codesegment/ScheduleCodeSegment.java Sun Dec 09 22:29:59 2012 +0900 @@ -21,10 +21,10 @@ new ThinkCodeSegment(phil.getName()); break; case TAKERIGHTFORK: - new TakeOneForkCodeSegment(phil.getName(), phil.getRightFork()); + new TakeRightForkCodeSegment(phil.getName(), phil.getRightFork()); break; case TAKELEFTFORK: - new TakeOneForkCodeSegment(phil.getName(), phil.getLeftFork()); + new TakeRightForkCodeSegment(phil.getName(), phil.getLeftFork()); break; /* case TAKEFORK:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/dpp/codesegment/TakeLeftForkCodeSegment.java Sun Dec 09 22:29:59 2012 +0900 @@ -0,0 +1,32 @@ +package alice.test.dpp.codesegment; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.test.dpp.model.Fork; +import alice.test.dpp.model.Philosophy; + +public class TakeLeftForkCodeSegment extends CodeSegment { + + Receiver arg1 = ids.create(CommandType.TAKE); + Receiver arg2 = ids.create(CommandType.TAKE); + + public TakeLeftForkCodeSegment(String pName, String forkName) { + arg1.setKey(pName); + arg2.setKey(forkName); + } + + @Override + public void run() { + Philosophy phil = arg1.asClass(Philosophy.class); + Fork fork = arg2.asClass(Fork.class); + if (fork.getFork(phil.getName())) { + phil.setState(Philosophy.State.EAT); + new EatCodeSegment(phil.getName()); + } else { + new TakeLeftForkCodeSegment(phil.getName(), phil.getRightFork()); + } + ods.update("local", phil.getName(), phil); + ods.update("local", fork.getForkName(), fork); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/dpp/codesegment/TakeRightForkCodeSegment.java Sun Dec 09 22:29:59 2012 +0900 @@ -0,0 +1,34 @@ +package alice.test.dpp.codesegment; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.test.dpp.model.Fork; +import alice.test.dpp.model.Philosophy; + +public class TakeRightForkCodeSegment extends CodeSegment { + + Receiver arg1 = ids.create(CommandType.TAKE); + Receiver arg2 = ids.create(CommandType.TAKE); + + public TakeRightForkCodeSegment(String pName, String forkName) { + arg1.setKey(pName); + arg2.setKey(forkName); + } + + @Override + public void run() { + Philosophy phil = arg1.asClass(Philosophy.class); + Fork fork = arg2.asClass(Fork.class); + if (fork.getFork(phil.getName())) { + phil.setState(Philosophy.State.TAKERIGHTFORK); + new TakeLeftForkCodeSegment(phil.getName(), phil.getLeftFork()); + } else { + new TakeRightForkCodeSegment(phil.getName(), phil.getRightFork()); + } + ods.update("local", phil.getName(), phil); + ods.update("local", fork.getForkName(), fork); + } + + +}