Tue, 15 Nov 2011, 01:31
A student writes: > On the examples shown if there was an invalid input there were only two > character that had to be checked to see if they were valid inputs. What I > wasn't sure about was if someone typed in more than two characters. Can we > assume the players are typing in only two characters or do we have to take > into account if they type in more. > > <<name withheld to protect the student worried about three characters>> Thanks for the question. Actually, it is not such a big deal as you might think, and you really do not have to worry about it. I will explain. If someone typed too many characters, for example A35, the pair A3 would be interpreted as a legal move, assuming there were still three rocks in row A. Then the ascii code for 5 would be the contents of the KBDR, the first character of the next move, and the ready bit would be set. TRAP x20 would input the 5, resulting in an illegal move since 5 is not the name of a row. From this point, users could continue to type illegal moves, since any pair (B4, for example) would generate 5B for the next move, and 4 as the first character of the move after that. Eventually someone could type a single character, and the game would be back in business! So, the long-winded answer is you do not have to worry about someone typing more than two characters. It will generate spurious illegal moves, but the players ought to be able to figure out what they are doing wrong and correct. And once they do, your program is back on track. Good luck finishing the game program, and enjoy playing it with your family when you are home for Thanksgiving. Yale Patt