ࡱ> XZW  bjbj .Bhh;;;;;OOOO4TOf3. 2222222$57 3; 3;; 3;;22=01tٹO02630f30F8F8,1F8;1 3 3.f3F8 : Lab 1: 15-111 Game of Tic Tac Toe  Due Date: Saturday May 24th, 2008 at 11:59 pm  Assignment Write a program to simulate a game of Tic Tac Toe.  Concepts: 2D Arrays, interactive I/O, String Parsing  Objectives: Understand multi-class programs Understand random number generators Use of 2D arrays interactive I/O String Processing  Description: Many computer games, such as strategy games, simulation games etc uses game boards that can be implemented as two dimensional arrays. In Java (and in many other languages) 2D arrays can be defined as an array of 1D arrays. For example a 2D matrix of characters (with dimensions 8x10) can be defined as follows. char[][] Board = new char[8][10] We can think of Board as a table with 8 rows (indexed from 0..7) and 10 columns(indexed from 0..9) Tic Tac Toe is played on a 3x3 board with two players alternating between Xs and Os, alternatively placing their respective marks on the board. First player succeeding in getting three of his marks in a row, column or diagonally wins the game. How do we design the classes to implement a tictactoe game? Let us think of the objects in a tictactoe game environment. We can think of four types of objects, tictactoe board, human player, dumb (or random) player and smart player. In this program we will only implement human player and dumb player. As an extra credit assignment you are encouraged to write a smart player that can analyze the board and make the best move. However that is not necessary. Let us begin with the following classes and methods. ClassMethodsTicTacToeclearBoard( ) isWin(int), winner(), printBoard( ), putMark(int, int)DriverMain( )HumanPlayermakeMove( TicTacToe B)ComputerPlayer (extra credit only)makeMove(TicTacToe B), findMove(TicTacToe B)DumbPlayermakeMove(TicTacToe B)The description of each method can be found in the source code. Your assignment is to complete the incomplete methods from TicTacToe, HumanPlayer and DumbPlayer classes. Testing your program You may use any kind of IDE such as eclipse to test your program. However, you need to make sure all programs run under Andrew linux. You should also check your program by creating different scenarios. Human vs Human First define, two human players and play them against each other. You can do this by initializing two HumanPlayers as follows. HumanPlayer Player1 = new HumanPlayer( ); HumanPlayer Player2 = new HumanPlayer( ); The program should prompt each player to enter position as a pair of valid integers. For example, two players taking turns can be shown as follows: > Player X : 0 1 > Player O : 1 1 Game should continue until one player wins or game is a draw. The program should correctly display the end of the game. For Example: The Player X wins Game is a draw Human vs Dumb Initialize a human player and a dumb player as follows. HumanPlayer Player1 = new HumanPlayer( ); DumbPlayer Player2 = new DumbPlayer( ); DumbPlayer will always make a random move. Therefore, human player should be able to usually beat the dumb player. Dumb vs Dumb First define, two dumb players and play them against each other. You can do this by initializing two DumbPlayers as follows. DumbPlayer Player1 = new DumbPlayer( ); DumbPlayer Player2 = new DumbPlayer( ); It would be interesting to see which dumb player wins and to see if starting dumb player has any advantage over the other one. Human vs Computer (extra credit only) For 10 extra points, you can complete the computerPlayer class. A computerPlayer in most cases must be able to defeat the dumbplayer. ComputerPlayer must be smart, analyzing the entire board to make a move. We suggest that at this point you use heuristics to find the best move. Later when you take courses such as 15-211, you will be able to learn techniques to analyze the game tree and make a good move. To test the ComputerPlayer against a dumbPlayer you can do DumbPlayer Player1 = new DumbPlayer( ); ComputerPlayer Player2 = new ComputerPlayer( );  Getting Started Download the lab1.zip file. Save the zip file to your desktop and unzip the files. Open the directory lab1. You should see the following files: Driver.java (the driver file) TicTacToe.java DumbPlayer.java HumanPlayer.java ComputerPlayer.java (extra credit only) smartPlayer.class // provided for testing your computerPlayer a copy of the lab description Most classes already have method headers. Your job is to fill them in with the appropriate code. DO NOT introduce any new public methods to given classes. You are allowed to define any new private methods to any of the classes provided. The driver program is complete. Do not change this unless when you are testing for various player combinations (eg: human vs human, human vs computer etc..)  Compiling and Running your code You must be able to compile and run your program from command line under Andrew linux. If you running on windows on command line, then you need to set the classPath so that javac and java commands are recognized from your working folder. See Blackboard/External links to find out how to set your classPath in windows. You can also use Eclipse to develop, debug and run your program. Your TA will show you how to install eclipse on your computer. However, the final zip folder must run under Andrew linux. The following commands are useful > javac *.java // compiles all source files > java Driver // runs the program  Handing in your Solution Your solutions should be in the form of .zip files. When we grade your solution we will unzip the folder and test the code. Your teaching assistants will show you how to zip up the files for submission. All labs are submitted to afs. The folder to submit your program is /afs/Andrew.cmu.edu/course/15/111-M08/handin/lab1/yourid  Grading Criteria The following grading criterion is strictly enforced. A program that does not compile - 0 points A program that is 24 hours later max of 50% of the grade A program that is more than 48 hours late 0 points Grading Programming Components TicTacToe class 40 points HumanPlayer class 20 points DumbPlayer class 20 points Driver class 10 points Style points 10 points (style points are based on indentation, proper use of variable names, structure of your program etc. Your TA can provide more guidance on this. Please ask)  $&')1BDJXYZefx$ 4 5 W X Y d f ˻ˣ˛˓zvvnfa]hk h;5h;h;5jph,UhQ. hF 5jh,UhIGh~Rh~R5j8h,UhF h,jh,Uhh h H*h3h~Rh 5jh Uh hQ.B* CJOJQJaJphh B* CJOJQJaJphhF B* CJOJQJaJph$&(XZ $ 5 E W Y "  % $$Ifa$gd3gd[8J & FgdF gd,gd gd    " ) * 1   . %0Gatv|}"]伷h,hZ5h,h,5j*h,U h[P5 hyC5hyChyC5h[PhhEzhTlh3h[8J5hgh.h[8Jh;h 5hzhQ.h hk:%&0u{o d$Ifgd3 $Ifgd[8J{kd $$Ifl0,"LL t0644 layt3uv}{{ $Ifgd[8J{kd$$Ifl0,"LL t0644 layt3{{ $Ifgd[8J{kd$$Ifl0,"LL t0644 layt3{{ $Ifgd[8J{kd$$Ifl0,"LL t0644 layt3{{ $Ifgd[8J{kd $$Ifl0,"LL t0644 layt38c$8Lzuuuuuuuuuugd gd,gd {kd$$Ifl0,"LL t0644 layt3 8"$Lz~9 \]np廉|rhOhzJ6>*hzJh[Ph[P5 h[P5hOh[P6>* h[P6>*h[Ph *h/hkh6h[Ph5hOh6>*h[Ph|5h|hw(Oh)sh[Ph 25h 2h,h56>*hh,h,h 5*L9c\]V~Sgd gdzJgd[Pgd & Fgd|gd pRUVs,SYZ^or{02۶zskh h 5 h h h 5hh 0J hSd0J5hSdhSd0J5h 0J5\hSd0J5\hSd hkh h h,h,jh,U h 5h[PhzJ5 h,5h,h[PhOhzJ6>* h[P6>*h[Ph[P56>**Sr2*OQj5ygd gd gd/ dd[$\$gd/gd, dd[$\$gd  & Fdd[$\$gdSd & Fdd[$\$gd 2@]5= 35fOPQ4~ϻ˯˯˯˫˯ˣhJxh!_hy>*h!_hJx>*hkJhLvjh/Uh3h jh/Uh/hH5h/h/5h/hHhHhH5 hH5jbh,Uh[h?4hiI5hiIh,h 5*e )  & FgdJx & Fgd/ & FgdLvgdLvgdLvgd/  h h/hJx,1h/ =!"#$% DdP  3 3"88DdP  3 3"88DdP  3 3"88DdP  3 3"88DdP  3 3"88$$If!vh5L5L#vL:V l t065Lyt3$$If!vh5L5L#vL:V l t065Lyt3$$If!vh5L5L#vL:V l t065Lyt3$$If!vh5L5L#vL:V l t065Lyt3$$If!vh5L5L#vL:V l t065Lyt3$$If!vh5L5L#vL:V l t065Lyt3DdP  3 3"88DdP  3 3"88DdP  3 3"88DdP   3 3"88DdP   3 3"88 ^ 2 0@P`p2( 0@P`p 0@P`p 0@P`p 0@P`p 0@P`p 0@P`p8XV~_HmH nH sH tH @`@ NormalCJ_HaJmH sH tH F@BF  Heading 4dd@&[$\$5\DA`D Default Paragraph FontRi@R  Table Normal4 l4a (k (No List B^@B  Normal (Web)dd[$\$Ng@N  HTML TypewriterCJOJPJQJ^JaJ4U4  Hyperlink >*phj#j [8J Table Grid7:V0PK![Content_Types].xmlj0Eжr(΢Iw},-j4 wP-t#bΙ{UTU^hd}㨫)*1P' ^W0)T9<l#$yi};~@(Hu* Dנz/0ǰ $ X3aZ,D0j~3߶b~i>3\`?/[G\!-Rk.sԻ..a濭?PK!֧6 _rels/.relsj0 }Q%v/C/}(h"O = C?hv=Ʌ%[xp{۵_Pѣ<1H0ORBdJE4b$q_6LR7`0̞O,En7Lib/SeеPK!kytheme/theme/themeManager.xml M @}w7c(EbˮCAǠҟ7՛K Y, e.|,H,lxɴIsQ}#Ր ֵ+!,^$j=GW)E+& 8PK!Ptheme/theme/theme1.xmlYOo6w toc'vuر-MniP@I}úama[إ4:lЯGRX^6؊>$ !)O^rC$y@/yH*񄴽)޵߻UDb`}"qۋJחX^)I`nEp)liV[]1M<OP6r=zgbIguSebORD۫qu gZo~ٺlAplxpT0+[}`jzAV2Fi@qv֬5\|ʜ̭NleXdsjcs7f W+Ն7`g ȘJj|h(KD- dXiJ؇(x$( :;˹! I_TS 1?E??ZBΪmU/?~xY'y5g&΋/ɋ>GMGeD3Vq%'#q$8K)fw9:ĵ x}rxwr:\TZaG*y8IjbRc|XŻǿI u3KGnD1NIBs RuK>V.EL+M2#'fi ~V vl{u8zH *:(W☕ ~JTe\O*tHGHY}KNP*ݾ˦TѼ9/#A7qZ$*c?qUnwN%Oi4 =3ڗP 1Pm \\9Mؓ2aD];Yt\[x]}Wr|]g- eW )6-rCSj id DЇAΜIqbJ#x꺃 6k#ASh&ʌt(Q%p%m&]caSl=X\P1Mh9MVdDAaVB[݈fJíP|8 քAV^f Hn- "d>znNJ ة>b&2vKyϼD:,AGm\nziÙ.uχYC6OMf3or$5NHT[XF64T,ќM0E)`#5XY`פ;%1U٥m;R>QD DcpU'&LE/pm%]8firS4d 7y\`JnίI R3U~7+׸#m qBiDi*L69mY&iHE=(K&N!V.KeLDĕ{D vEꦚdeNƟe(MN9ߜR6&3(a/DUz<{ˊYȳV)9Z[4^n5!J?Q3eBoCM m<.vpIYfZY_p[=al-Y}Nc͙ŋ4vfavl'SA8|*u{-ߟ0%M07%<ҍPK! ѐ'theme/theme/_rels/themeManager.xml.relsM 0wooӺ&݈Э5 6?$Q ,.aic21h:qm@RN;d`o7gK(M&$R(.1r'JЊT8V"AȻHu}|$b{P8g/]QAsم(#L[PK-![Content_Types].xmlPK-!֧6 +_rels/.relsPK-!kytheme/theme/themeManager.xmlPK-!Ptheme/theme/theme1.xmlPK-! ѐ' theme/theme/_rels/themeManager.xml.relsPK]  B p2  %uLS 8@0(  B S  ? OLE_LINK1 OLE_LINK2FJ&)ENv&/0:>CDGT^cjknps]b + 8 C S ^ c n ~ J K 9 D S ^ c m }   s ~ c e  &4?IV`oy~.3yORz})W=C8 L c w - 0 A D S _ c v   oz~3333333333333333ABIJW0v .r*NQj)ABIJv ,w 8'j+`^+i)v~g-0]EHYj܀qHo8eXa}x^hhh^h`OJQJo(hHh88^8`OJQJ^Jo(hHoh^`OJQJo(hHh  ^ `OJQJo(hHh  ^ `OJQJ^Jo(hHohxx^x`OJQJo(hHhHH^H`OJQJo(hHh^`OJQJ^Jo(hHoh^`OJQJo(hH^`CJOJQJo(^`CJOJQJo(opp^p`CJOJQJo(@ @ ^@ `CJOJQJo(^`CJOJQJo(^`CJOJQJo(^`CJOJQJo(^`CJOJQJo(PP^P`CJOJQJo(^`o(. ^`hH. pLp^p`LhH. @ @ ^@ `hH. ^`hH. L^`LhH. ^`hH. ^`hH. PLP^P`LhH.hh^h`OJPJQJ^Jo(88^8`OJQJ^Jo(hHo^`OJQJo(hH  ^ `OJQJo(hH  ^ `OJQJ^Jo(hHoxx^x`OJQJo(hHHH^H`OJQJo(hH^`OJQJ^Jo(hHo^`OJQJo(hH^`o(. ^`hH. pLp^p`LhH. @ @ ^@ `hH. ^`hH. L^`LhH. ^`hH. ^`hH. PLP^P`LhH.^`CJOJQJo(^`CJOJQJo(opp^p`CJOJQJo(@ @ ^@ `CJOJQJo(^`CJOJQJo(^`CJOJQJo(^`CJOJQJo(^`CJOJQJo(PP^P`CJOJQJo(^`o(. ^`hH. pLp^p`LhH. @ @ ^@ `hH. ^`hH. L^`LhH. ^`hH. ^`hH. PLP^P`LhH.^`.^`.pp^p`.@ @ ^@ `.^`.^`.^`.^`.PP^P`.Xa}w 8EHYv i)+Ho~g-                                             >=3;OZ/F   . [t@h& * 2?469yCIG[8JkJzJw(O~R!_zcSdTlJxn)sLvAzHiI y/g,XQ'aQ.qk[PEz58|6 %Mzg@JxtL @JJpJJX@UnknownG*Ax Times New Roman5Symbol3. *Cx Arial7. [ @Verdana?= *Cx Courier New;WingdingsA BCambria Math"qhit&( -( -42QHP? 2!xx%Lab 1: 15-111  Game of Tic Tac Toe Ananda Gunaguna,        Oh+'0|  8 D P\dlt(Lab 1: 15-111 Game of Tic Tac Toe  Ananda GunaNormalguna5Microsoft Office Word@<8@I@ ٹ(՜.+,0$ hp  Carnegie Mellon University-  &Lab 1: 15-111 Game of Tic Tac Toe Title  !#$%&'()+,-./0123456789:;<=>?@ABCDEFHIJKLMNPQRSTUVYRoot Entry F/ٹ[Data "1Table*r8WordDocument.BSummaryInformation(GDocumentSummaryInformation8OCompObjy  F'Microsoft Office Word 97-2003 Document MSWordDocWord.Document.89q