diff --git a/Client.java b/Client.java index b69e41c..ad96d69 100755 --- a/Client.java +++ b/Client.java @@ -30,6 +30,7 @@ public class Client { private JPanel boardPanel; private static final String Columns = "ABCDEFGH"; public static final int BLACK = 0, WHITE = 1; + public static String boardoutput = ""; public Client() { initializeGui(); @@ -86,10 +87,12 @@ public class Client { Insets buttonMargin = new Insets(0,0,0,0); for(int r = 0; r < boardSquares.length; ++r) { for(int c = 0; c < boardSquares.length; ++c) { + final int selectrow = r; + final int selectcol = c; Action selectPiece = new AbstractAction("") { @Override public void actionPerformed(ActionEvent e) { - sendLocation(); + sendLocation(selectrow, selectcol); } }; JButton b = new JButton(); @@ -190,11 +193,13 @@ public class Client { } } - public void sendLocation() { - + public void sendLocation(int r, int c) { + //debugging. + System.out.println("row: " + r + " col: " + c); + boardoutput += "" + r + "" + c; } - public static void main (String[] args) { + public static void main (String[] args) throws InterruptedException { Scanner keyboard = new Scanner(System.in); String hostname = args[0]; int portnum = Integer.parseInt(args[1]); @@ -233,11 +238,10 @@ public class Client { frame.pack(); frame.setMinimumSize(frame.getSize()); frame.setVisible(true); + userInput = stdIn.readLine(); + output.println(userInput); - while(!end && (userInput != null)) { - userInput = stdIn.readLine(); - output.println(userInput); - output.flush(); + while(!end) { char[] buffer = new char[256]; in.read(buffer, 0, 256); for(int i = 0; i < buffer.length; ++i) { @@ -247,6 +251,13 @@ public class Client { } System.out.println(String.valueOf(buffer).trim()); window.updateBoard(String.valueOf(buffer).trim()); + while(boardoutput.length() < 4) { + Thread.sleep(100); + } + System.out.println(boardoutput); + output.println(boardoutput); + output.flush(); + boardoutput = ""; } output.close(); in.close(); diff --git a/Server.cpp b/Server.cpp index 4221292..0c96b26 100644 --- a/Server.cpp +++ b/Server.cpp @@ -20,6 +20,40 @@ void error(const char *msg) exit(1); } +string tempParse(string move) { + string output = ""; + int tempa = move[0] - '0'; + int tempb = move[1] - '0'; + int tempc = move[2] - '0'; + int tempd = move[3] - '0'; + + //cout << "move: " << move << " " << tempa << " " << tempb << " " << tempc << " " << tempd << "\n"; + + for(int c = 0; c < 4; c++) { + if(!isdigit(move[c])) { + //cout << "\nfjdkjfjd\n"; + return move; + } + } + if(tempa == (tempc + 1)) { + //cout << "\nTest\n"; + if(tempb == tempd) { + output = ((char)('A' + tempb)) + to_string(8 - tempa) + "_f"; + } + else if(tempb == (tempd + 1)) { + output = ((char)('A' + tempb)) + to_string(8 - tempa) + "_l"; + } + else if(tempb == (tempd - 1)) { + output = ((char)('A' + tempb)) + to_string(8 - tempa) + "_r"; + } + } + else { + return move; + } + cout << "Debugging: " << output << "\n\n"; + return output; +} + int main(int argc, char *argv[]) { int sockfd, newsockfd, portno; @@ -113,6 +147,9 @@ int main(int argc, char *argv[]) n = read(newsockfd,buffer,255); move = buffer; bzero(buffer,256); + //cout << move << "\n\n"; + move = tempParse(move); + //cout << move << "\n\n"; e.getBoard()->interpret(move,(*e.getBoard())); if(e.getBoard()->isValid()) {