<commit_before>package ca.sfu.client;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import ca.sfu.cmpt431.facility.Board;
import ca.sfu.cmpt431.facility.BoardOperation;
import ca.sfu.cmpt431.facility.Border;
import ca.sfu.cmpt431.facility.Comrade;
import ca.sfu.cmpt431.facility.Neighbour;
import ca.sfu.cmpt431.facility.Outfits;
import ca.sfu.cmpt431.message.Message;
import ca.sfu.cmpt431.message.MessageCodeDictionary;
import ca.sfu.cmpt431.message.join.JoinOutfitsMsg;
import ca.sfu.cmpt431.message.join.JoinRequestMsg;
import ca.sfu.cmpt431.message.join.JoinSplitMsg;
import ca.sfu.cmpt431.message.regular.RegularBoardReturnMsg;
import ca.sfu.cmpt431.message.regular.RegularBorderMsg;
import ca.sfu.cmpt431.message.regular.RegularConfirmMsg;
import ca.sfu.cmpt431.message.regular.RegularUpdateNeighbourMsg;
import ca.sfu.network.MessageReceiver;
import ca.sfu.network.MessageSender;

public class Client {

	private static final int SERVER_PORT = 6560;
	private static final String SERVER_IP = "192.168.3.11";
	private Comrade  server;
	
	private int myPort;
	private String myIp;
	private MessageReceiver Receiver;
	private RegularConfirmMsg myConfirmMessage;
	
	private int status;
	private Outfits outfit;
	
	private int neiUpdCount;

	public boolean[] up ;
	public boolean[] down;
	public boolean[] left;
	public boolean[] right;
	public boolean upperLeft;
	public boolean upperRight;
	public boolean lowerLeft;
	public boolean lowerRight;
	
	private int borderCount = 0;
	
	public Client() {
		while(true){
			Random r = new Random(); 
			myPort = r.nextInt(55535)+10000;
			try{
				System.out.println("trying port " + myPort);
				Receiver = new MessageReceiver(myPort);
				System.out.println("port " + myPort + "is ok");
				break;
			}
			catch(Exception e){
				System.out.println("port " + myPort + "is occupied");
			}
		}
	}
	
	public void startClient(String ip) throws IOException, InterruptedException {
		myIp = ip;
		MessageSender svsdr = new MessageSender(SERVER_IP, SERVER_PORT);
		server = new Comrade(MessageCodeDictionary.ID_SERVER, SERVER_PORT, SERVER_IP, svsdr);
		JoinRequestMsg Request = new JoinRequestMsg(myPort);
		server.sender.sendMsg(Request);
		status = 1;
		while(true){
			if(!Receiver.isEmpty()){
//				System.out.println("status :" + status);
				Message msg = (Message) Receiver.getNextMessageWithIp().extracMessage();
				switch(status) {
//					case 0:
//						server.sender.sendMsg(new RegularConfirmMsg(-1));
//						status = 1;
//						break;
					case 1:
						repairOutfit((JoinOutfitsMsg) msg);
						sendNeiUpdMsg();
						if(neiUpdCount > 0)
							status = 2;
						else
							status = 3;
						break;
					case 2:
						neiUpdCount--;
						if(neiUpdCount <= 0){
							server.sender.sendMsg(myConfirmMessage);
							status = 3;
						}
						break;
					case 3:
						int msgType = msg.getMessageCode();
						if(msgType == MessageCodeDictionary.REGULAR_NEXTCLOCK) {
							sendBorderToNeighbours();
							if(isBorderMessageComplete())
								computeAndReport();
							else
								status = 4;
						}
						else if (msgType == MessageCodeDictionary.REGULAR_UPDATE_NEIGHBOUR)
							handleNeighbourUpdate((RegularUpdateNeighbourMsg)msg);
						else if (msgType == MessageCodeDictionary.JOIN_SPLIT) {
							handleSplit((JoinSplitMsg) msg);
							System.out.println("!!!!!!!!!\nReceived split command\n!!!!!!!!!\n");
							status = 5;<commit_msg>client debug<commit_after>package ca.sfu.client;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import ca.sfu.cmpt431.facility.Board;
import ca.sfu.cmpt431.facility.BoardOperation;
import ca.sfu.cmpt431.facility.Border;
import ca.sfu.cmpt431.facility.Comrade;
import ca.sfu.cmpt431.facility.Neighbour;
import ca.sfu.cmpt431.facility.Outfits;
import ca.sfu.cmpt431.message.Message;
import ca.sfu.cmpt431.message.MessageCodeDictionary;
import ca.sfu.cmpt431.message.join.JoinOutfitsMsg;
import ca.sfu.cmpt431.message.join.JoinRequestMsg;
import ca.sfu.cmpt431.message.join.JoinSplitMsg;
import ca.sfu.cmpt431.message.regular.RegularBoardReturnMsg;
import ca.sfu.cmpt431.message.regular.RegularBorderMsg;
import ca.sfu.cmpt431.message.regular.RegularConfirmMsg;
import ca.sfu.cmpt431.message.regular.RegularUpdateNeighbourMsg;
import ca.sfu.network.MessageReceiver;
import ca.sfu.network.MessageSender;

public class Client {

	private static final int SERVER_PORT = 6560;
	private static final String SERVER_IP = "192.168.3.11";
	private Comrade  server;
	
	private int myPort;
	private String myIp;
	private MessageReceiver Receiver;
	private RegularConfirmMsg myConfirmMessage;
	
	private int status;
	private Outfits outfit;
	
	private int neiUpdCount;

	public boolean[] up ;
	public boolean[] down;
	public boolean[] left;
	public boolean[] right;
	public boolean upperLeft;
	public boolean upperRight;
	public boolean lowerLeft;
	public boolean lowerRight;
	
	private int borderCount = 0;
	
	public Client() {
		while(true){
			Random r = new Random(); 
			myPort = r.nextInt(55535)+10000;
			try{
				System.out.println("trying port " + myPort);
				Receiver = new MessageReceiver(myPort);
				System.out.println("port " + myPort + "is ok");
				break;
			}
			catch(Exception e){
				System.out.println("port " + myPort + "is occupied");
			}
		}
	}
	
	public void startClient(String ip) throws IOException, InterruptedException {
		myIp = ip;
		MessageSender svsdr = new MessageSender(SERVER_IP, SERVER_PORT);
		server = new Comrade(MessageCodeDictionary.ID_SERVER, SERVER_PORT, SERVER_IP, svsdr);
		JoinRequestMsg Request = new JoinRequestMsg(myPort);
		server.sender.sendMsg(Request);
		status = 1;
		while(true){
			if(!Receiver.isEmpty()){
//				System.out.println("status :" + status);
				Message msg = (Message) Receiver.getNextMessageWithIp().extracMessage();
				switch(status) {
//					case 0:
//						server.sender.sendMsg(new RegularConfirmMsg(-1));
//						status = 1;
//						break;
					case 1:
						repairOutfit((JoinOutfitsMsg) msg);
						sendNeiUpdMsg();
						if(neiUpdCount > 0)
							status = 2;
						else
							status = 3;
						break;
					case 2:
						neiUpdCount--;
						if(neiUpdCount <= 0){
							server.sender.sendMsg(myConfirmMessage);
							status = 3;
						}
						break;
					case 3:
						int msgType = msg.getMessageCode();
						if(msgType == MessageCodeDictionary.REGULAR_NEXTCLOCK) {
							sendBorderToNeighbours();
							if(isBorderMessageComplete())
								computeAndReport();
							else
								status = 4;
						}
						else if (msgType == MessageCodeDictionary.REGULAR_UPDATE_NEIGHBOUR)
							handleNeighbourUpdate((RegularUpdateNeighbourMsg)msg);
						else if (msgType == MessageCodeDictionary.JOIN_SPLIT) {
							System.out.println("!!!!!!!!!\nReceived split command\n!!!!!!!!!\n");
							handleSplit((JoinSplitMsg) msg);
							status = 5;
{'fraction_non_alphanumeric': 0.1147801009372747, 'fraction_numerical': 0.023936553713049747, 'mean_word_length': 3.737704918032787, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3098269', 'n_tokens_mistral': 2856, 'n_tokens_neox': 2248, 'n_words': 464}