public String EndMove(String state, Long matchId, String id1, String id2, int meID){
String turn= DataOperation.getTurnWithMatchId(matchId);
turn = turn.equals(id1) ? id1 : id2;
DataOperation.updateMatch(new Long(matchId), state, turn);
channelService.sendMessage(new ChannelMessage(id2,"C,"+state));
channelService.sendMessage(new ChannelMessage(id1,"C,"+state));
Date currentDate = new Date();
String currentDateString = DataOperation.dateToString(currentDate);
String myRankAndRD = DataOperation.getRankAndRD(id1);
String myRankString = myRankAndRD.split(" ")[0];
String myRDString = myRankAndRD.split(" ")[1];
int myRank = Integer.valueOf(myRankString);
int myRD = Integer.valueOf(myRDString);
double myS;
String oppRankAndRD = DataOperation.getRankAndRD(id2);
String oppRankString = oppRankAndRD.split(" ")[0];
String oppRDString = oppRankAndRD.split(" ")[1];
int oppRank = Integer.valueOf(oppRankString);
int oppRD = Integer.valueOf(oppRDString);
double oppS;
State st=StateSerializer.unserializeState(state);
if(meID==0){
if(st.getPlayers().get(0).getResult()==GameOver.Result.WIN){
myS=1.0;
if(st.getPlayers().get(1).getResult()==GameOver.Result.WIN)
oppS=1.0;
else if(st.getPlayers().get(1).getResult()==GameOver.Result.LOSE)
oppS=0;
else
oppS=0.5;
}
else if(st.getPlayers().get(0).getResult()==GameOver.Result.LOSE){
myS=0.0;
if(st.getPlayers().get(1).getResult()==GameOver.Result.WIN)
oppS=1.0;
else if(st.getPlayers().get(1).getResult()==GameOver.Result.LOSE)
oppS=0;
else
oppS=0.5;
}else{
myS=0.5;
if(st.getPlayers().get(1).getResult()==GameOver.Result.WIN)
oppS=1.0;
else if(st.getPlayers().get(1).getResult()==GameOver.Result.LOSE)
oppS=0;
else
oppS=0.5;
}
}else{
if(st.getPlayers().get(1).getResult()==GameOver.Result.WIN){
myS=1.0;
if(st.getPlayers().get(0).getResult()==GameOver.Result.WIN)
oppS=1.0;
else if(st.getPlayers().get(0).getResult()==GameOver.Result.LOSE)
oppS=0;
else
oppS=0.5;
}
else if(st.getPlayers().get(1).getResult()==GameOver.Result.LOSE){
myS=0.0;
if(st.getPlayers().get(0).getResult()==GameOver.Result.WIN)
oppS=1.0;
else if(st.getPlayers().get(0).getResult()==GameOver.Result.LOSE)
oppS=0;
else
oppS=0.5;
}else{
myS=0.5;
if(st.getPlayers().get(0).getResult()==GameOver.Result.WIN)
oppS=1.0;
else if(st.getPlayers().get(0).getResult()==GameOver.Result.LOSE)
oppS=0;
else
oppS=0.5;
}
}
String rankAndRD1=DataOperation.updateGamePeriodData(id1, currentDateString, myRD,(double) myRank, oppS);
String rank1=rankAndRD1.split(" ")[0];
String RD1=rankAndRD1.split(" ")[1];
channelService.sendMessage(new ChannelMessage(id1,"R"+","+rank1+","+RD1));
String rankAndRD2=DataOperation.updateGamePeriodData(id2, currentDateString,oppRD, (double) oppRank, myS);
String rank2=rankAndRD2.split(" ")[0];
String RD2=rankAndRD2.split(" ")[1];
channelService.sendMessage(new ChannelMessage(id2,"R"+","+rank2+","+RD2));
return state;
}