Mercurial > hg > Members > nobuyasu > Alice > DPPAlice
diff src/alice/test/dpp/codesegment/TakeForkCodeSegment.java @ 14:33727db069c2
add ScheduleCodeSegment. modified CodeSegment
author | one |
---|---|
date | Wed, 28 Nov 2012 17:41:42 +0900 |
parents | bfaaebb50a2e |
children | 7e91e919a7de |
line wrap: on
line diff
--- a/src/alice/test/dpp/codesegment/TakeForkCodeSegment.java Wed Nov 28 16:21:34 2012 +0900 +++ b/src/alice/test/dpp/codesegment/TakeForkCodeSegment.java Wed Nov 28 17:41:42 2012 +0900 @@ -8,30 +8,31 @@ public class TakeForkCodeSegment extends CodeSegment { - Philosophy phil; Receiver arg1 = ids.create(CommandType.TAKE); Receiver arg2 = ids.create(CommandType.TAKE); + Receiver arg3 = ids.create(CommandType.TAKE); + + public TakeForkCodeSegment(String pName, String rFork, String lFork) { + arg1.setKey(pName); + arg2.setKey(rFork); + arg3.setKey(lFork); + } - public TakeForkCodeSegment(Philosophy p) { - phil = p; - arg1.setKey(phil.getLeftFork()); - arg2.setKey(phil.getRightFork()); - } - @Override public void run() { - System.out.println(phil.getName() + " is trying to take the fork."); - Fork leftFork = arg1.asClass(Fork.class); + Philosophy phil = arg1.asClass(Philosophy.class); Fork rightFork = arg2.asClass(Fork.class); - if (leftFork.getFork(phil) && rightFork.getFork(phil) ) { - new EatCodeSegment(phil); + Fork leftFork = arg3.asClass(Fork.class); + System.out.println(phil.getName() + " is trying to take the fork."); + if (leftFork.getFork(phil.getName()) && rightFork.getFork(phil.getName()) ) { + phil.setState(Philosophy.State.EAT); } else { - leftFork.onTheTable(phil); - rightFork.onTheTable(phil); - new TakeForkCodeSegment(phil); + leftFork.onTheTable(phil.getName()); + rightFork.onTheTable(phil.getName()); } + new ScheduleCodeSegment(phil.getName()); + ods.update("local", phil.getName(), phil); ods.update("local", leftFork.getForkName(), leftFork); ods.update("local", rightFork.getForkName(), rightFork); } - }