1 | package genius.core;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 |
|
---|
5 | import genius.core.actions.Action;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * @author Reyhan
|
---|
9 | *
|
---|
10 | */
|
---|
11 |
|
---|
12 | public class NegoRound {
|
---|
13 |
|
---|
14 | private ArrayList<NegoTurn> partyActionList;
|
---|
15 | private int currentTurnIndex;
|
---|
16 | private int currentRoundNo;
|
---|
17 | private ArrayList<Class> actionsTerminateSessionWithSuccess;
|
---|
18 | private ArrayList<Class> actionsTerminateSessionWithFailure;
|
---|
19 |
|
---|
20 | public NegoRound() {
|
---|
21 |
|
---|
22 | this.setPartyActionList(new ArrayList<NegoTurn>());
|
---|
23 | this.setActionsTerminateSessionWithFailure(new ArrayList<Class>());
|
---|
24 | this.setActionsTerminateSessionWithSuccess(new ArrayList<Class>());
|
---|
25 | this.currentTurnIndex=0;
|
---|
26 | this.setCurrentRoundNo(1);
|
---|
27 |
|
---|
28 | }
|
---|
29 |
|
---|
30 | public NegoRound(ArrayList<NegoTurn> partyActionList, int numberOfTurnInARound) {
|
---|
31 |
|
---|
32 | this.setPartyActionList(partyActionList);
|
---|
33 | this.setActionsTerminateSessionWithFailure(new ArrayList<Class>());
|
---|
34 | this.setActionsTerminateSessionWithSuccess(new ArrayList<Class>());
|
---|
35 | this.currentTurnIndex=0;
|
---|
36 | this.setCurrentRoundNo(1);
|
---|
37 | }
|
---|
38 |
|
---|
39 | public NegoRound(ArrayList<NegoTurn> partyActionList, ArrayList<Class> actionsTerminateWithSuccess, ArrayList<Class> actionsTerminateWithFailure,int numberOfTurnInARound) {
|
---|
40 |
|
---|
41 | this.setPartyActionList(partyActionList);
|
---|
42 | this.setActionsTerminateSessionWithFailure(actionsTerminateWithFailure);
|
---|
43 | this.setActionsTerminateSessionWithSuccess(actionsTerminateWithSuccess);
|
---|
44 | this.currentTurnIndex=0;
|
---|
45 | this.setCurrentRoundNo(1);
|
---|
46 | }
|
---|
47 |
|
---|
48 | //clone
|
---|
49 | public NegoRound(NegoRound negoRound){
|
---|
50 |
|
---|
51 | this.partyActionList=negoRound.getPartyActionList();
|
---|
52 | this.currentTurnIndex=negoRound.getCurrentTurnIndex();
|
---|
53 | this.currentRoundNo=negoRound.getCurrentRoundNo();
|
---|
54 | this.actionsTerminateSessionWithFailure=negoRound.getActionsTerminateSessionWithFailure();
|
---|
55 | this.actionsTerminateSessionWithSuccess=negoRound.getActionsTerminateSessionWithSuccess();
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected int getCurrentTurnIndex(){
|
---|
59 | return currentTurnIndex;
|
---|
60 | }
|
---|
61 |
|
---|
62 | public ArrayList<Class> getActionsTerminateSessionWithFailure(){
|
---|
63 | return actionsTerminateSessionWithFailure;
|
---|
64 | }
|
---|
65 |
|
---|
66 | public void setActionsTerminateSessionWithFailure(ArrayList<Class> actions) {
|
---|
67 | actionsTerminateSessionWithFailure=actions;
|
---|
68 | }
|
---|
69 |
|
---|
70 | public void addActionTerminateSessionWithFailure(Class action) {
|
---|
71 | actionsTerminateSessionWithFailure.add(action);
|
---|
72 | }
|
---|
73 |
|
---|
74 | public void removeActionTeminateSessionWithFailure (Class action) {
|
---|
75 |
|
---|
76 | actionsTerminateSessionWithFailure.remove(action);
|
---|
77 | }
|
---|
78 |
|
---|
79 | public void clearActionsTerminateSessionWithFailure () {
|
---|
80 | actionsTerminateSessionWithFailure=new ArrayList<Class>();
|
---|
81 | }
|
---|
82 |
|
---|
83 | public ArrayList<Class> getActionsTerminateSessionWithSuccess(){
|
---|
84 | return actionsTerminateSessionWithSuccess;
|
---|
85 | }
|
---|
86 |
|
---|
87 | public void setActionsTerminateSessionWithSuccess(ArrayList<Class> actions) {
|
---|
88 | actionsTerminateSessionWithSuccess=actions;
|
---|
89 | }
|
---|
90 |
|
---|
91 | public void addActionTerminateSessionWithSuccess(Class action) {
|
---|
92 | actionsTerminateSessionWithSuccess.add(action);
|
---|
93 | }
|
---|
94 |
|
---|
95 | public void removeActionTeminateSessionWithSuccess (Class action) {
|
---|
96 |
|
---|
97 | actionsTerminateSessionWithSuccess.remove(action);
|
---|
98 | }
|
---|
99 |
|
---|
100 | public void clearActionsTerminateSessionWithSuccess () {
|
---|
101 | actionsTerminateSessionWithSuccess=new ArrayList<Class>();
|
---|
102 | }
|
---|
103 |
|
---|
104 | public int getCurrentRoundNo() {
|
---|
105 | return currentRoundNo;
|
---|
106 | }
|
---|
107 |
|
---|
108 | public void setCurrentRoundNo(int currentRoundNo) {
|
---|
109 | this.currentRoundNo = currentRoundNo;
|
---|
110 | }
|
---|
111 |
|
---|
112 | public ArrayList<NegoTurn> getPartyActionList() {
|
---|
113 | return partyActionList;
|
---|
114 | }
|
---|
115 |
|
---|
116 | public void setPartyActionList(ArrayList<NegoTurn> partyActionList) {
|
---|
117 | this.partyActionList = partyActionList;
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | public void addPartyActions(NegoTurn partyAction) {
|
---|
122 | partyActionList.add(partyAction);
|
---|
123 | }
|
---|
124 |
|
---|
125 | public NegoTurn getCurrentPartyAndValidActions() {
|
---|
126 | return (partyActionList.get(currentTurnIndex));
|
---|
127 | }
|
---|
128 |
|
---|
129 | public int getCurrentPartyIndex() {
|
---|
130 | return (partyActionList.get(currentTurnIndex).getPartyIndex());
|
---|
131 | }
|
---|
132 |
|
---|
133 | public ArrayList<Class> getCurrentPartysValidActions() {
|
---|
134 | return (partyActionList.get(currentTurnIndex).getValidActions());
|
---|
135 | }
|
---|
136 |
|
---|
137 | public boolean setNextTurn(){
|
---|
138 |
|
---|
139 | currentTurnIndex= (currentTurnIndex+1) % partyActionList.size();
|
---|
140 | if (currentTurnIndex==0){
|
---|
141 | currentRoundNo++;
|
---|
142 | return true;
|
---|
143 | }
|
---|
144 | return false;
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 | public boolean isCurrentActionValid(Action currentAction){
|
---|
149 |
|
---|
150 | if (getCurrentPartysValidActions().contains(currentAction.getClass()))
|
---|
151 | return true;
|
---|
152 | else
|
---|
153 | return false;
|
---|
154 | }
|
---|
155 |
|
---|
156 | public boolean isDeadlineReached(int maxRound){
|
---|
157 |
|
---|
158 | if (currentRoundNo>maxRound)
|
---|
159 | return true;
|
---|
160 | else return false;
|
---|
161 | }
|
---|
162 |
|
---|
163 | public boolean doesTerminateWithSuccess(Action currentAction) {
|
---|
164 |
|
---|
165 | if (actionsTerminateSessionWithSuccess.contains(currentAction.getClass()))
|
---|
166 | return true;
|
---|
167 | else
|
---|
168 | return false;
|
---|
169 | }
|
---|
170 |
|
---|
171 | public boolean doesTerminateWithFailure(Action currentAction) {
|
---|
172 |
|
---|
173 | if (actionsTerminateSessionWithFailure.contains(currentAction.getClass()))
|
---|
174 | return true;
|
---|
175 | else
|
---|
176 | return false;
|
---|
177 | }
|
---|
178 |
|
---|
179 | }
|
---|
180 |
|
---|