Mercurial > hg > Members > nobuyasu > Alice > DPPAlice
changeset 29:d45de183af46 draft
modified TakeRightForkCodeSegment and TakeLeftForkCodeSegment to use ForkStateTakeCodeSegment.
author | one |
---|---|
date | Tue, 11 Dec 2012 16:55:24 +0900 |
parents | e8ec5f7f43c0 |
children | 5eb22e2f7169 |
files | src/alice/test/dpp/codesegment/fork/ForkStateTakeCodeSegment.java src/alice/test/dpp/codesegment/philosophy/CheckForkOwnerCodeSegment.java src/alice/test/dpp/codesegment/philosophy/TakeForkManagerCodeSegment.java src/alice/test/dpp/codesegment/philosophy/TakeLeftForkCodeSegment.java src/alice/test/dpp/codesegment/philosophy/TakeRightForkCodeSegment.java |
diffstat | 5 files changed, 6 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/test/dpp/codesegment/fork/ForkStateTakeCodeSegment.java Tue Dec 11 16:29:10 2012 +0900 +++ b/src/alice/test/dpp/codesegment/fork/ForkStateTakeCodeSegment.java Tue Dec 11 16:55:24 2012 +0900 @@ -21,6 +21,7 @@ public void run() { Philosophy phil = arg1.asClass(Philosophy.class); Fork fork = arg2.asClass(Fork.class); + System.out.println(phil.getName() + " try to take " + fork.getForkName()); fork.takeFork(phil.getName()); new CheckForkOwnerCodeSegment(phil.getName(), fork.getForkName()); ods.update("local", phil.getName(), phil);
--- a/src/alice/test/dpp/codesegment/philosophy/CheckForkOwnerCodeSegment.java Tue Dec 11 16:29:10 2012 +0900 +++ b/src/alice/test/dpp/codesegment/philosophy/CheckForkOwnerCodeSegment.java Tue Dec 11 16:55:24 2012 +0900 @@ -21,6 +21,7 @@ Philosophy phil = arg1.asClass(Philosophy.class); Fork fork = arg2.asClass(Fork.class); if (fork.ownerEquals(phil.getName())) { + phil.checkForkFlag(fork.getForkName()); } new TakeForkManagerCodeSegment(phil.getName());
--- a/src/alice/test/dpp/codesegment/philosophy/TakeForkManagerCodeSegment.java Tue Dec 11 16:29:10 2012 +0900 +++ b/src/alice/test/dpp/codesegment/philosophy/TakeForkManagerCodeSegment.java Tue Dec 11 16:55:24 2012 +0900 @@ -19,7 +19,7 @@ if (phil.hasLeftFork && phil.hasRightFork) { phil.setState(Philosophy.State.EAT); new EatCodeSegment(phil.getName()); - } else if (phil.hasLeftFork) { + } else if (phil.hasRightFork) { phil.setState(Philosophy.State.TAKELEFTFORK); new TakeLeftForkCodeSegment(phil.getName(), phil.getLeftFork()); } else {
--- a/src/alice/test/dpp/codesegment/philosophy/TakeLeftForkCodeSegment.java Tue Dec 11 16:29:10 2012 +0900 +++ b/src/alice/test/dpp/codesegment/philosophy/TakeLeftForkCodeSegment.java Tue Dec 11 16:55:24 2012 +0900 @@ -3,6 +3,7 @@ import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; +import alice.test.dpp.codesegment.fork.ForkStateTakeCodeSegment; import alice.test.dpp.datasegment.Fork; import alice.test.dpp.datasegment.Philosophy; @@ -21,12 +22,7 @@ Philosophy phil = arg1.asClass(Philosophy.class); Fork fork = arg2.asClass(Fork.class); System.out.println(phil.getName() + " take left fork."); - if (fork.takeFork(phil.getName())) { - phil.setState(Philosophy.State.EAT); - new EatCodeSegment(phil.getName()); - } else { - new TakeLeftForkCodeSegment(phil.getName(), phil.getLeftFork()); - } + new ForkStateTakeCodeSegment(phil.getName(), phil.getLeftFork()); ods.update("local", phil.getName(), phil); ods.update("local", fork.getForkName(), fork); }
--- a/src/alice/test/dpp/codesegment/philosophy/TakeRightForkCodeSegment.java Tue Dec 11 16:29:10 2012 +0900 +++ b/src/alice/test/dpp/codesegment/philosophy/TakeRightForkCodeSegment.java Tue Dec 11 16:55:24 2012 +0900 @@ -21,14 +21,8 @@ public void run() { Philosophy phil = arg1.asClass(Philosophy.class); Fork fork = arg2.asClass(Fork.class); + System.out.println(phil.getName() + " take right fork."); new ForkStateTakeCodeSegment(phil.getName(), fork.getForkName()); - - if (fork.takeFork(phil.getName())) { - phil.setState(Philosophy.State.TAKELEFTFORK); - 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); }