1 import java. u t i l. ArrayList ; 2 import java. u t i l. L i s t ; 4 /
|
|
- Wilfrid Garrison
- 6 years ago
- Views:
Transcription
1 1 import java. u t i l. ArrayList ; 2 import java. u t i l. L i s t ; 3 4 / 5 The c l a s s {@code Othello } r e p r e s e n t s the game Othello i t s e l f. 6 All game l o g i c i s done in t h i s c l a s s. 7 8 The Java Doc can be found h e r e : 9 <a h r e f="http : / /www. martin thoma. de/ programmieren o t h e l l o 1adf234d3fS/"> 10 martin thoma. de/ programmieren o t h e l l o 1adf234d3fS </a> 11 Martin Thoma 13 / p u b l i c c l a s s Othello { 16 / Error message : a p l a y e r already moved / 17 p u b l i c s t a t i c f i n a l S t r i n g ERR_PLAYER_MOVED 18 = "Cannot add hole area. A p l a y e r did move. " ; / Error message : no a c t i v e game / 21 p u b l i c s t a t i c f i n a l S t r i n g ERR_NO_ACTIVE_GAME = "No a c t i v e game. " ; / Error message : the move t a r g e t i s n t on the board / 24 p u b l i c s t a t i c f i n a l S t r i n g ERR_OFFBOARD_MOVE 25 = "The move p o s i t i o n has to be on the board. " ; / Error message : a c o l o r i s in the f o r a hole s p e c i f i e d r e c t a n g l e / 28 p u b l i c s t a t i c f i n a l S t r i n g ERR_COLOR_IN_RECTANGLE 29 = "You can t p l a c e the hole here. There are c o l o r p i e c e s. " ; / Error message : the s p e c i f i e d r e c t a n g l e i s n t v a l i d / 32 p u b l i c s t a t i c f i n a l S t r i n g ERR_NO_VALID_RECTANGLE = "The s p e c i f i e d " ; 33 + " r e c t a n g l e i s n t v a l i d. " 34 + " Valid i s something l i k e A1 : B3 or A1 : A1. The f i r s t p o s i t i o n " ; 35 + " has to be on the top l e f t. " ; / The c u r r e n t p l a y e r. Always s t a r t with black. / 38 p r i v a t e F i e l d c u r r e n t P l a y e r = F i e l d.black; / I s the c u r r e n t game s t i l l in p r o g r e s s? / 41 p r i v a t e boolean isrunning = true ; / Has a l r e a d y a move command been submitted? / 44 p r i v a t e boolean submittedmove = f a l s e ; / The board with a l l p i e c e s / 47 p u b l i c f i n a l Board board ; p r i v a t e f i n a l i n t [ ] [ ] a d j a c t a n t F i e l d s = {{ 1, 1}, {0, 1}, {1, 1}, 50 { 1, 0}, {1, 0}, { 1, 1}, {0, 1}, {1, 1}}; / 53 Constructor f o r Othello. 54 I t i s p o s s i b l e, that the game i s f i n i s h e d as soon as i t i s c r e a t e d. width t h e width o f t h e board h e i g h t the h e i g h t o f the board 57 / 1
2 58 p u b l i c Othello ( i n t width, i n t height ) { 59 t h i s. board = new Board ( width, h eight ) ; 60 checkstate ( ) ; 61 } / 64 Constructor f o r Othello with a given s t a r t s i t u a t i o n. 65 I t i s p o s s i b l e, that the game i s f i n i s h e d as soon as i t i s c r e a t e d. width t h e width o f t h e board h e i g h t the h e i g h t o f the board s i t u a t i o n the s i t u a t i o n the p l a y e r wants to s t a r t with 69 / 70 p u b l i c Othello ( i n t width, i n t height, S t r i n g s i t u a t i o n ) { 71 t h i s. board = new Board ( width, height, s i t u a t i o n ) ; 72 checkstate ( ) ; 73 } / 76 Checks f o r a l l c o n s t r u c t o r s i f black can make a move. 77 I f black can t i t s the turn o f white. I f white can t move e i t h e r, 78 the game i s f i n i s h e d. 79 / 80 p r i v a t e void checkstate ( ) { 81 i f (! ismovepossible ( F i e l d.black) ) { 82 i f (! ismovepossible ( F i e l d.white) ) { 83 // i f no moves are p o s s i b l e, the game i s i n s t a n t l y f i n i s h e d 84 t h i s. isrunning = f a l s e ; 85 } e l s e { 86 // i f black can t move but white can, i t s whites turn 87 t h i s. c u r r e n t P l a y e r = F i e l d.white; 88 } 89 } 90 } / 93 This method checks i f any move i s p o s s i b l e f o r p l a y e r p l a y e r the c o l o r o f the p l a y e r you want to check {@code true } i f any move i s p o s s i b l e, 96 o t h e r w i s e {@code f a l s e } 97 / 98 p r i v a t e boolean ismovepossible ( F i e l d p l a y e r ) { 99 return ( getpossiblemoves ( p l a y e r ). s i z e ( ) > 0) ; 100 } / 103 Get a l i s t o f a l l p o s s i b l e moves. p l a y e r the p l a y e r whose p o s s i b l e moves you want to get a l i s t o f a l l p o s s i b l e moves 106 / 107 p u b l i c List <Position > getpossiblemoves ( F i e l d p l a y e r ) { 108 i f (! isrunning ) { 109 throw new I l l e g a l S t a t e E x c e p t i o n (ERR_NO_ACTIVE_GAME) ; 110 } List <Position > possiblemoves = new ArrayList<Position >() ; P o s i t i o n pos ; 115 f o r ( i n t x = 0 ; x < board. width ; x++) { 2
3 116 f o r ( i n t y = 0 ; y < board. h eight ; y++) { 117 pos = new P o s i t i o n ( x, y ) ; 118 i f ( ismovepositionvalid ( pos ) 119 && ( getnrofswitches ( player, pos ) > 0) ) { 120 possiblemoves. add ( pos ) ; 121 } 122 } 123 } return possiblemoves ; 126 } / 129 Checks i f a p o s i t i o n on the board has a c o l o r. 130 I f the p o s i t i o n i s not v a l i d ( e. g. n e g a t i v e array index ) i t 131 r e t u r n s {@code f a l s e }. pos the p o s i t i o n you want to check {@code true } i f a c o l o r i s at t h i s p o s i t i o n, 134 o t h e r w i s e {@code f a l s e } 135 / 136 p r i v a t e boolean haspiece ( P o s i t i o n pos ) { 137 boolean returnval = f a l s e ; i f ( board. ispositiononboard ( pos ) && board. get ( pos )!= n u l l 140 && board. get ( pos )!= F i e l d.hole) { 141 returnval = true ; 142 } return returnval ; 145 } / 148 Check i f a move p o s i t i o n i s v a l i d. This checks i f the p o s i t i o n 149 e x i s t s on the board, i f i t i s empty and i f a p i e c e i s adjacent. pos the p o s i t i o n you want to check {@code true } i f the move p o s i t i o n can be valid, 152 o t h e r w i s e {@code f a l s e } 153 / 154 p r i v a t e boolean ismovepositionvalid ( P o s i t i o n pos ) { 155 boolean ismovepositionvalid = f a l s e ; i f (! board. ispositiononboard ( pos ) ) { 158 r eturn f a l s e ; 159 } f o r ( i n t [ ] f i e l d : a d j a c t a n t F i e l d s ) { 162 P o s i t i o n tmp = new P o s i t i o n ( pos. x + f i e l d [ 0 ], 163 pos. y + f i e l d [ 1 ] ) ; 164 i f ( haspiece (tmp) ) { 165 ismovepositionvalid = true ; 166 } 167 } i f ( board. get ( pos. x, pos. y )!= n u l l ) { 170 // a p i e c e i s a l r e a dy on the f i e l d 171 ismovepositionvalid = f a l s e ; 172 } 173 3
4 174 return ismovepositionvalid ; 175 } / 178 Set the c u r r e n t p l a y e r to the next p l a y e r. 179 / 180 p r i v a t e void nextplayer ( ) { 181 i f (! isrunning ) { 182 throw new I l l e g a l S t a t e E x c e p t i o n (ERR_NO_ACTIVE_GAME) ; 183 } i f ( c u r r e n t P l a y e r == F i e l d.black) { 186 c u r r e n t P l a y e r = F i e l d.white; 187 } e l s e { 188 c u r r e n t P l a y e r = F i e l d.black; 189 } 190 } / 193 Make a move, i f p o s s i b l e and return a code that i n d i c a t e s what 194 happened. pos the p o s i t i o n you want to s e t the next p i e c e on 0 i f the p l a y e r could move, i f the p l a y e r could not move, i f the next r e g u l a r p l a y e r had to pass, i f the game ended with t h i s move 200 / 201 p u b l i c i n t move( P o s i t i o n pos ) { 202 i f (! isrunning ) { 203 throw new I l l e g a l S t a t e E x c e p t i o n (ERR_NO_ACTIVE_GAME) ; 204 } i n t returncode = 1; 207 i n t s w i t c h e s ; i f (! board. ispositiononboard ( pos ) ) { 210 throw new IllegalArgumentException (ERR_OFFBOARD_MOVE) ; 211 } i f ( ismovepositionvalid ( pos ) 214 && ( getnrofswitches ( currentplayer, pos ) > 0) ) { 215 board. s e t ( pos, c u r r e n t P l a y e r ) ; // switch a l l p i e c e s in between 218 f o r ( i n t [ ] d i r e c t i o n : a d j a c t a n t F i e l d s ) { 219 s w i t c h e s = getnrofincludedpieces ( currentplayer, pos, 220 d i r e c t i o n [ 0 ], d i r e c t i o n [ 1 ] ) ; 221 i f ( s w i t c h e s > 0) { 222 s w i t c h P i e c e s ( currentplayer, pos, d i r e c t i o n [ 0 ], d i r e c t i o n [ 1 ] ) ; 223 } 224 } // switch to the next p l a y e r 227 nextplayer ( ) ; i f (! ismovepossible ( getcurrentplayer ( ) ) ) { 230 F i e l d nextplayer = getwaitingplayer ( ) ; 4
5 231 i f ( ismovepossible ( nextplayer ) ) { 232 nextplayer ( ) ; 233 returncode = 1 ; 234 } e l s e { 235 s e t F i n i s h e d ( ) ; 236 returncode = 2 ; 237 } 238 } e l s e { 239 returncode = 0 ; 240 } submittedmove = true ; 243 } return returncode ; 246 } / 249 Get the c u r r e n t p l a y e r. the c u r r e n t p l a y e r 251 / 252 p u b l i c F i e l d getcurrentplayer ( ) { 253 return c u r r e n t P l a y e r ; 254 } / 257 This method determines the number o f p i e c e s o f the opponent 258 between the given p o s i t i o n and the next p i e c e o f the given p l a y e r. p l a y e r The p l a y e r. pos the p o s i t i o n o f one p i e c e o f t h i s p l a y e r. xdir t h i s has to be 1, 0 or means i t goes to the r i g h t, 1 to the l e f t means i t doesn t change the x d i r e c t i o n. ydir t h i s has to be 1, 0 or means i t goes to the bottom, 1 to the top means i t doesn t change the y d i r e c t i o n. the number o f p i e c e s o f the opponent between the given p o s i t i o n 268 and the next p i e c e o f the given p l a y e r. 269 / p r i v a t e i n t getnrofincludedpieces ( F i e l d player, P o s i t i o n pos, i n t xdir, i n t ydir ) { 272 i n t s w i t c h e s = 0 ; 273 i n t opponentcount = 0 ; 274 F i e l d opponent = ( p l a y e r == F i e l d.white? F i e l d.black : F i e l d.white ) ; f o r ( i n t tmp = 1 ; 277 // stop the loop i f you re no l o n g e r on the board 278 ( pos. x + tmp xdir >= 0) // important i f you go to the l e f t 279 && ( pos. x + tmp xdir < board. width ) // important i f you go to the r i g h t 280 && ( pos. y + tmp ydir >= 0) // important i f you go to the bottom 281 && ( pos. y + tmp ydir < board. height ) ; // important i f you go to the top 282 tmp++) { 5
6 F i e l d p i e c e = board. get ( pos. x + tmp xdir, pos. y + tmp ydir ) ; i f ( p i e c e == p l a y e r ) { 287 s w i t c h e s += opponentcount ; 288 opponentcount = 0 ; 289 break ; 290 } e l s e i f ( p i e c e == F i e l d.hole) { 291 r eturn 0 ; 292 } e l s e i f ( p i e c e == opponent ) { 293 opponentcount++; 294 } e l s e i f ( p i e c e == n u l l ) { 295 r eturn 0 ; 296 } 297 } return s w i t c h e s ; 300 } / 303 Switch a l l p i e c e s from the opponent o f p l a y e r in the given d i r e c t i o n. 304 Make sure that in the given d i r e c t i o n i s one o f the p i e c e s o f p l a y e r at the end. p l a y e r the given p l a y e r who s e t the new p i e c e pos the p o s i t i o n where you want to s t a r t xdir one part o f the d i r e c t i o n ydir other part o f the d i r e c t i o n 309 / 310 p r i v a t e void s w i t c h P i e c e s ( F i e l d player, P o s i t i o n pos, i n t xdir, i n t ydir ) { 311 i f (! isrunning ) { 312 throw new I l l e g a l S t a t e E x c e p t i o n (ERR_NO_ACTIVE_GAME) ; 313 } F i e l d opponent = ( p l a y e r == F i e l d.white? F i e l d.black : F i e l d.white ) ; // t h i s ends always with the break as one p i e c e o f p l a y e r has to be at the end 318 f o r ( i n t tmp = 1 ; ; tmp++) { 319 i f ( board. get ( pos. x + tmp xdir, pos. y + tmp ydir ) == p l a y e r ) { 320 break ; 321 } e l s e i f ( board. get ( pos. x + tmp xdir, pos. y + tmp ydir ) == opponent ) { 322 board. s e t ( pos. x + tmp xdir, pos. y + tmp ydir, p l a y e r ) ; 323 } 324 } 325 } / 328 Return the number o f p i e c e s that get switched when p l a y e r s e t s 329 a new p i e c e on ( x y ) p l a y e r the given p l a y e r pos the p o s i t i o n o f the new p i e c e the number o f switched p i e c e s. 6
7 333 / 334 p r i v a t e i n t getnrofswitches ( F i e l d player, P o s i t i o n pos ) { 335 i n t s w i t c h e s = 0 ; f o r ( i n t [ ] d i r e c t i o n : a d j a c t a n t F i e l d s ) { 338 s w i t c h e s += getnrofincludedpieces ( player, pos, d i r e c t i o n [ 0 ], d i r e c t i o n [ 1 ] ) ; 339 } return s w i t c h e s ; 342 } / 345 Return the r e s u l t. an array with two elements where the f i r s t element 347 r e p r e s e n t s the p o i n t s 348 o f the white p l a y e r and the second element the p o i n t s o f the second p l a y e r 349 / 350 p u b l i c i n t [ ] g e t R e s u l t ( ) { 351 i n t [ ] r e s u l t = new i n t [ 2 ] ; 352 r e s u l t [ 0 ] = countpieces ( F i e l d.white) ; 353 r e s u l t [ 1 ] = countpieces ( F i e l d.black) ; 354 return r e s u l t ; 355 } // t h i s method counts the p i e c e s o f one p l a y e r on the board 358 p r i v a t e i n t countpieces ( F i e l d p l a y e r ) { 359 i n t counter = 0 ; 360 f o r ( i n t x = 0 ; x < board. width ; x++) { 361 f o r ( i n t y = 0 ; y < board. h eight ; y++) { 362 i f ( board. get ( x, y ) == p l a y e r ) { 363 counter++; 364 } 365 } 366 } 367 return counter ; 368 } / 371 Mark the game as f i n i s h e d. 372 / 373 p u b l i c void s e t F i n i s h e d ( ) { 374 i f (! isrunning ) { 375 throw new I l l e g a l S t a t e E x c e p t i o n (ERR_NO_ACTIVE_GAME) ; 376 } isrunning = f a l s e ; 379 } / 382 Getter f o r isrunning. {@code true } i f the game i s s t i l l in progress, 384 o t h e r w i s e {@code f a l s e } 385 / 386 p u b l i c boolean isrunning ( ) { 387 return isrunning ; 388 } 7
8 / 391 Checks i f the r e c t a n g l e i s within the borders o f the board and 392 i f the f i r s t p o s i t i o n i s at the top l e f t and the second i s at 393 the bottom r i g h t. r e c t a n g l e the r e c t a n g l e {@code true } i f the r e c t a n g l e i s v a l i d according to the 396 s p e c i f i c a t i o n, o t h e r w i s e {@code f a l s e } 397 / 398 p u b l i c boolean i s V a l i d R e c t a n g l e ( P o s i t i o n [ ] r e c t a n g l e ) { 399 i f (! board. ispositiononboard ( r e c t a n g l e [ 0 ] ) ) { 400 r eturn f a l s e ; 401 } e l s e i f (! board. ispositiononboard ( r e c t a n g l e [ 1 ] ) ) { 402 r eturn f a l s e ; 403 } e l s e i f ( r e c t a n g l e [ 0 ]. x > r e c t a n g l e [ 1 ]. x ) { 404 r eturn f a l s e ; 405 } e l s e i f ( r e c t a n g l e [ 0 ]. y > r e c t a n g l e [ 1 ]. y ) { 406 r eturn f a l s e ; 407 } e l s e { 408 r eturn true ; 409 } 410 } / 413 Check i f a p i e c e i s in the s p e c i f i e d r e c t a n g l e. r e c t a n g l e the s p e c i f i e d r e c t a n g l e {@code true } i f a p i e c e i s in the s p e c i f i e d r e c t a n g l e, 416 o t h e r w i s e {@code f a l s e } 417 / 418 p u b l i c boolean i s C o l o r I n R e c t a n g l e ( P o s i t i o n [ ] r e c t a n g l e ) { 419 i f (! i s V a l i d R e c t a n g l e ( r e c t a n g l e ) ) { 420 throw new IllegalArgumentException (ERR_NO_VALID_RECTANGLE) ; 421 } f o r ( i n t x = r e c t a n g l e [ 0 ]. x ; x <= r e c t a n g l e [ 1 ]. x ; x++) { 424 f o r ( i n t y = r e c t a n g l e [ 0 ]. y ; y <= r e c t a n g l e [ 1 ]. y ; y++) { 425 i f ( board. get ( x, y ) == F i e l d.black board. get ( x, y ) == F i e l d.white) { 426 r eturn true ; 427 } 428 } 429 } return f a l s e ; 432 } / 435 Make an hole i n t o the board i f p o s s i b l e. r e c t a n g l e The edges o f the r e c t a n g l e o f the hole {@code true } i f a hole could be created, o t h e r w i s e {@code f a l s e } 438 / 439 p u b l i c boolean makehole ( P o s i t i o n [ ] r e c t a n g l e ) { 440 i f ( submittedmove ) { 441 throw new I l l e g a l S t a t e E x c e p t i o n (ERR_PLAYER_MOVED) ; 442 } e l s e i f (! i s V a l i d R e c t a n g l e ( r e c t a n g l e ) ) { 443 throw new IllegalArgumentException (ERR_NO_VALID_RECTANGLE) ; 444 } e l s e i f ( i s C o l o r I n R e c t a n g l e ( r e c t a n g l e ) ) { 8
9 445 throw new IllegalArgumentException (ERR_COLOR_IN_RECTANGLE) ; 446 } f o r ( i n t x = r e c t a n g l e [ 0 ]. x ; x <= r e c t a n g l e [ 1 ]. x ; x++) { 449 f o r ( i n t y = r e c t a n g l e [ 0 ]. y ; y <= r e c t a n g l e [ 1 ]. y ; y++) { 450 board. s e t ( x, y, F i e l d.hole) ; 451 } 452 } // Switch to the other p l a y e r i f the c u r r e n t p l a y e r can t move any l o n g e r 455 i f ( getpossiblemoves ( c u r r e n t P l a y e r ). s i z e ( ) == 0) { 456 nextplayer ( ) ; 457 } return true ; 460 } / 463 Was a move a l r e a d y submitted? {@code true } i f a move was a lready submitted, o t h e r w i s e f a l s e } 465 / 466 p u b l i c boolean wasmovesubmitted ( ) { 467 return submittedmove ; 468 } / 471 This method aborts the c u r r e n t game and r e t u r n s the r e s u l t. the r e s u l t as an i n t array with two elements where {@code r e s u l t [ 0 ] } 473 r e p r e s e n t s the p o i n t s o f the white p l a y e r and {@code r e s u l t [ 1 ] } r e p r e s e n t s the 474 p o i n t s o f the black p l a y e r 475 / 476 p u b l i c i n t [ ] abortgame ( ) { 477 i n t [ ] r e s u l t = g e t R e s u l t ( ) ; 478 s e t F i n i s h e d ( ) ; 479 return r e s u l t ; 480 } / 483 Get the p l a y e r who can t make a turn by now. the p l a y e r who can t make a turn by now 485 / 486 p u b l i c F i e l d getwaitingplayer ( ) { 487 return getcurrentplayer ( ) == F i e l d.black? F i e l d.white : F i e l d. BLACK; 488 } 489 } Othello.java 9
1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal
Präsenzstunden Today In the same room as in the first week Assignment 5 Felix Friedrich, Lars Widmer, Fabian Stutz TA lecture, Informatics II D-BAUG March 18, 2014 HIL E 15.2 15:00-18:00 Timon Gehr (arriving
More informationLists, Stacks, and Queues (plus Priority Queues)
Lists, Stacks, and Queues (plus Priority Queues) The structures lists, stacks, and queues are composed of similar elements with different operations. Likewise, with mathematics: (Z, +, 0) vs. (Z,, 1) List
More informationDM507 - Algoritmer og Datastrukturer Project 1
DM507 - Algoritmer og Datastrukturer Project 1 Christian Skjøth Mat-Øk 280588 Morten Olsen Mat-Øk 090789 19. marts 2012 Task 1 - Double for-loop So, first we needed to create an instance of the class File
More informationMAT 1302B Mathematical Methods II
MAT 1302B Mathematical Methods II Alistair Savage Mathematics and Statistics University of Ottawa Winter 2015 Lecture 3 Alistair Savage (uottawa) MAT 1302B Mathematical Methods II Winter 2015 Lecture 3
More informationElementary Sorts 1 / 18
Elementary Sorts 1 / 18 Outline 1 Rules of the Game 2 Selection Sort 3 Insertion Sort 4 Shell Sort 5 Visualizing Sorting Algorithms 6 Comparing Sorting Algorithms 2 / 18 Rules of the Game Sorting is the
More informationCMSC 132, Object-Oriented Programming II Summer Lecture 6:
CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 6: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 6.1 Singly
More informationIntroduction to Computing II (ITI1121) FINAL EXAMINATION
Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Identification
More informationCS-140 Fall 2018 Test 2 Version Practice Nov. 12, Name:
CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) T F : If a child overrides its parent
More informationMURA Office hours Thurs at 12-1pm in CIT 546 Contact for more info.
Course Announcements Lecture capture has begun, available from Lectures page. First two and a half weeks are packed. Testing lab done, HTML started, and Stars due next Friday. Department has a lot of student
More informationExercise 1: Formal Tools and Techniques (10 points)
EXAM System Validation (191401) 13:45-17:15 0-07-01 The exercises are worth a total of 100 points. The final grade for the course is (hw 1+hw )/+exam/10, provided that you obtain at least 50 points for
More informationExtensibility Patterns: Extension Access
Design Patterns and Frameworks Dipl.-Medieninf. Christian Piechnick INF 2080 christian.piechnick@tu-dresden.de Exercise Sheet No. 5 Software Technology Group Institute for SMT Department of Computer Science
More informationSoftware Testing Lecture 2
Software Testing Lecture 2 Justin Pearson September 25, 2014 1 / 1 Test Driven Development Test driven development (TDD) is a way of programming where all your development is driven by tests. Write tests
More information1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ;
1 Trees The next major set of data structures belongs to what s called Trees. They are called that, because if you try to visualize the structure, it kind of looks like a tree (root, branches, and leafs).
More informationCS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018
CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) T X F : If a child overrides its parent
More informationBoardGame: A MiniDraw extension
BoardGame: A MiniDraw extension Henrik Bærbak Christensen Status: Draft. November 29, 2010 Chapter 1 Boardgame Architecture The MiniDraw framework is described in Chapter 30 in Flexible, Reliable Software.
More informationÜbung Informatik I - Programmierung - Blatt 7
RHEINISCH- WESTFÄLISCHE TECHNISCHE HOCHSCHULE AACHEN LEHR- UND FORSCHUNGSGEBIET INFORMATIK II RWTH Aachen D-52056 Aachen GERMANY http://programmierung.informatik.rwth-aachen.de LuFG Informatik II Prof.
More informationExercise 1 (15 points)
Exam System Validation (214012) 8:45-12:15, 25-06-2010 The exercises are worth a total of 90 points. The final grade is 10+pts 10. The exam is open book: copies of slides/papers/notes/etc. are allowed.
More informationClass Notes: Solving Simultaneous Linear Equations by Gaussian Elimination. Consider a set of simultaneous linear equations:
METR/OCN 465: Computer Programming with Applications in Meteorology and Oceanography Dr Dave Dempsey Dept of Geosciences, SFSU Class Notes: Solving Simultaneous Linear Equations by Gaussian Elimination
More informationSolution suggestions for examination of Logic, Algorithms and Data Structures,
Department of VT12 Software Engineering and Managment DIT725 (TIG023) Göteborg University, Chalmers 24/5-12 Solution suggestions for examination of Logic, Algorithms and Data Structures, Date : April 26,
More informationObject Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20
Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20 This is a closed-book exam. Any form of cheating or lying will not be tolerated. Students can get zero scores and/or fail the class and/or
More informationThe Snowball sprite contains 2 costumes, a normal costume, and one that shows which direction the snowball is facing.
Snowball Fight Introduction In this project you re going to make a game in which you have to throw snowballs at a target. You ll use the mouse pointer to angle the snowball and the spacebar to choose the
More informationPreptests 55 Answers and Explanations (By Ivy Global) Section 4 Logic Games
Section 4 Logic Games Questions 1 6 There aren t too many deductions we can make in this game, and it s best to just note how the rules interact and save your time for answering the questions. 1. Type
More informationComputer Science Introductory Course MSc - Introduction to Java
Computer Science Introductory Course MSc - Introduction to Java Lecture 3:,, Pablo Oliveira ENST Outline 1 2 3 Definition An exception is an event that indicates an abnormal condition
More informationIntroduction to Computing II (ITI 1121) FINAL EXAMINATION
Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Identification
More information1 Java Night Countdown (30%)
Midterm Examination Problem Sheet TIME: 04/18/2009, 19:00 21:00 This is a open-textbook exam. You can use the Absolute Java textbook as your reference during the exam. Any other references are not allowed.
More informationWEEK 3.1 MORE ON KARNAUGH MAPS
WEEK 3. MORE ON KARNAUGH MAPS Don t Cares Sometimes, we might have inputs and it doesn t matter what the output is; i.e., we don t care what the output is. These situations are called don t cares. Rather
More informationHW3, for MATH441, STAT461, STAT561, due September 20th
HW3, for MATH441, STAT461, STAT561, due September 20th 1. Suppose A and B are independent with 0 < P (A), P (B) < 1. Show that A c and B c are also independent. Solution. We know that P (AB) = P (A)P (B)
More informationLatches. October 13, 2003 Latches 1
Latches The second part of CS231 focuses on sequential circuits, where we add memory to the hardware that we ve already seen. Our schedule will be very similar to before: We first show how primitive memory
More information8.3 Hamiltonian Paths and Circuits
8.3 Hamiltonian Paths and Circuits 8.3 Hamiltonian Paths and Circuits A Hamiltonian path is a path that contains each vertex exactly once A Hamiltonian circuit is a Hamiltonian path that is also a circuit
More informationExam Question Examples 2015
Exam Question Examples 2015 Henrik Bærbak Christensen November 24, 2015 1 0.1 Test-driven development. The Breakthrough game is played on a standard chess board, using 16 white and 16 black pawns that
More informationLaboratory II. Exploring Digital Logic
Laboratory II Exploring Digital Logic Abstract Few devices in the world are as ubiquitous as the seven-segment display. This device, which was invented in the 1960 s, can be found everywhere from digital
More informationCS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:
CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If a child overrides
More informationSOLUTION: SOLUTION: SOLUTION:
Convert R and S into nondeterministic finite automata N1 and N2. Given a string s, if we know the states N1 and N2 may reach when s[1...i] has been read, we are able to derive the states N1 and N2 may
More informationDiscrete Mathematics and Probability Theory Fall 2013 Vazirani Note 1
CS 70 Discrete Mathematics and Probability Theory Fall 013 Vazirani Note 1 Induction Induction is a basic, powerful and widely used proof technique. It is one of the most common techniques for analyzing
More informationAlpha-Beta Pruning: Algorithm and Analysis
Alpha-Beta Pruning: Algorithm and Analysis Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Introduction Alpha-beta pruning is the standard searching procedure used for solving
More informationOne Pile Nim with Arbitrary Move Function
One Pile Nim with Arbitrary Move Function by Arthur Holshouser and Harold Reiter Arthur Holshouser 3600 Bullard St. Charlotte, NC, USA, 28208 Harold Reiter Department of Mathematics UNC Charlotte Charlotte,
More informationb) Connect the oscilloscope across the potentiometer that is on the breadboard. Your instructor will draw the circuit diagram on the board.
Geiger Counter Experiments and The Statistics of Nuclear Decay Using a Geiger Mueller tube, there are a number of experiments we can do. In the classroom there are two different types of Geiger Counters:
More informationHeaps Induction. Heaps. Heaps. Tirgul 6
Tirgul 6 Induction A binary heap is a nearly complete binary tree stored in an array object In a max heap, the value of each node that of its children (In a min heap, the value of each node that of its
More informationDigital Control of Electric Drives
Digital Control of Electric Drives Logic Circuits - equential Description Form, Finite tate Machine (FM) Czech Technical University in Prague Faculty of Electrical Engineering Ver.. J. Zdenek 27 Logic
More informationLecture 5: Sep. 23 &25
CIS 2168 Data Structures Fall 2014 Lecturer: Anwar Mamat Lecture 5: Sep. 23 &25 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 5.1 Doubly Linked
More informationUsing a Microcontroller to Study the Time Distribution of Counts From a Radioactive Source
Using a Microcontroller to Study the Time Distribution of Counts From a Radioactive Source Will Johns,Eduardo Luiggi (revised by Julia Velkovska, Michael Clemens September 11, 2007 Abstract In this lab
More informationCourse Announcements. John Jannotti (cs32) Scope, Collections & Generics Feb 8, / 1
Course Announcements Stars is due tomorrow. Stars grades should be out by next Monday. Javascript lab out today. How you make interactive webby GUIs. Today we re going to cover a bit of a hodge podge.
More informationApache Quarks for Developers April 13, 2016
Apache Quarks for Developers April 13, 2016 Apache Quarks is currently undergoing Incubation at the Apache Software Foundation. Quarks Development Console - Topics Who am I? Susan Cline, Quarks committer,
More informationStacks. Definitions Operations Implementation (Arrays and Linked Lists) Applications (system stack, expression evaluation) Data Structures 1 Stacks
Stacks Definitions Operations Implementation (Arrays and Linked Lists) Applications (system stack, expression evaluation) Data Structures 1 Stacks Stacks: Definitions and Operations A LIFO list: Last In,
More informationOutline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University
COMP SCI / SFWR ENG 2S03 Department of Computing and Software McMaster University Week 10: November 7 - November 11 Outline 1 Resource 2 Introduction Nodes Illustration 3 Usage Accessing and Modifying
More informationLecture 14: Nov. 11 & 13
CIS 2168 Data Structures Fall 2014 Lecturer: Anwar Mamat Lecture 14: Nov. 11 & 13 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 14.1 Sorting
More informationHomework set 2 - Solutions
Homework set 2 - Solutions Math 495 Renato Feres Simulating a Markov chain in R Generating sample sequences of a finite state Markov chain. The following is a simple program for generating sample sequences
More informationAlgorithms for Playing and Solving games*
Algorithms for Playing and Solving games* Andrew W. Moore Professor School of Computer Science Carnegie Mellon University www.cs.cmu.edu/~awm awm@cs.cmu.edu 412-268-7599 * Two Player Zero-sum Discrete
More informationProblem Decomposition: One Professor s Approach to Coding
Problem Decomposition: One Professor s Approach to Coding zombie[1] zombie[3] Fewer Buuuuugs zombie[4] zombie[2] zombie[5] zombie[0] Fundamentals of Computer Science I Overview Problem Solving Understand
More informationMathematics for Computer Science Exercises for Week 10
Mathematics for Computer Science Exercises for Week 10 Silvio Capobianco Last update: 7 November 2018 Problems from Section 9.1 Problem 9.1. Prove that a linear combination of linear combinations of integers
More informationThe Midterm Exam. Hsuan-Tien Lin. Department of CSIE, NTU. OOP Class, April 26-27, 2010
The Midterm Exam Hsuan-Tien Lin Department of CSIE, NTU OOP Class, April 26-27, 2010 H.-T. Lin (NTU CSIE) The Midterm Exam OOP 04/26-27/2010 0 / 20 Java Night Countdown I 1 (2%) What is the fully-qualified
More informationCS 480/680: GAME ENGINE PROGRAMMING
CS 480/680: GAME ENGINE PROGRAMMING PHYSICS 2/14/2013 Santiago Ontañón santi@cs.drexel.edu https://www.cs.drexel.edu/~santi/teaching/2013/cs480-680/intro.html Outline Student Presentations Basics on Rigid
More informationReading and Writing. Mathematical Proofs. Slides by Arthur van Goetham
Reading and Writing Mathematical Proofs Slides by Arthur van Goetham What is a proof? Why explanations are not proofs What is a proof? A method for establishing truth What establishes truth depends on
More informationSFWR ENG 3S03: Software Testing
(Slide 1 of 69) Dr. Ridha Khedri Writing in Department of Computing and Software, McMaster University Canada L8S 4L7, Hamilton, Ontario Acknowledgments: Material based on [HT03] Unit Testing in Java with
More informationDiscrete Mathematics and Probability Theory Spring 2014 Anant Sahai Note 3
EECS 70 Discrete Mathematics and Probability Theory Spring 014 Anant Sahai Note 3 Induction Induction is an extremely powerful tool in mathematics. It is a way of proving propositions that hold for all
More informationAdvanced topic: Space complexity
Advanced topic: Space complexity CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Chinese University of Hong Kong Fall 2016 1/28 Review: time complexity We have looked at how long it takes to
More informationAlpha-Beta Pruning: Algorithm and Analysis
Alpha-Beta Pruning: Algorithm and Analysis Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Introduction Alpha-beta pruning is the standard searching procedure used for 2-person
More informationLimiting Reactants. When the limiting reactant is used up THE REACTION STOPS!
Limiting Reactants Limiting Reactants The limiting reactant is 1) A reactant (one of the things you start with) and 2) The reactant that makes the least product Or 3) The reactant that is used up first
More informationPrelim 2[Solutions] Solutions. 1. Short Answer [18 pts]
Prelim [Solutions]. Short Answer [8 pts] (a) [3 pts] In a model/view/controller, Swing is likely to be part of (there may be more than one): i. the model ii. the view iii. the controller The view and the
More informationAlpha-Beta Pruning: Algorithm and Analysis
Alpha-Beta Pruning: Algorithm and Analysis Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Introduction Alpha-beta pruning is the standard searching procedure used for 2-person
More informationThomas Jefferson Invitational Open in Informatics
Thomas Jefferson Invitational Open in Informatics Sample Problems (With Solutions) Version 2.01.1 By programmers, For programmers Preface Preface Welcome to the TJ IOI Sample Problems document. Here, you
More informationVisualizing the distributions of the escape paths of quaternion fractals
Visualizing the distributions of the escape paths of quaternion fractals S. Halayka October 25, 2018 Abstract The length, displacement, and magnitude distributions of the escape paths of the points in
More informationDaily Start Monday TT 2015.notebook. November 30, 2015
1 EVERYDAY MATH LESSON 4.1 Created by: Brian Salco Rocky River City Schools 2015 2 For today's lesson you will need: * Dry erase board * Dry erase marker & eraser * Math Journal 1 * Pencil * Toolkit Clocks
More informationNo Solution Equations Let s look at the following equation: 2 +3=2 +7
5.4 Solving Equations with Infinite or No Solutions So far we have looked at equations where there is exactly one solution. It is possible to have more than solution in other types of equations that are
More information10.1. Randomness and Probability. Investigation: Flip a Coin EXAMPLE A CONDENSED LESSON
CONDENSED LESSON 10.1 Randomness and Probability In this lesson you will simulate random processes find experimental probabilities based on the results of a large number of trials calculate theoretical
More informationHints about SPHERES Loop Dynamics
Hints about SPHERES Loop Dynamics Goals In this tutorial you will look at: SPHERES dynamics related to Newton s First Law Test out 4 different What if? Scenarios to see how your code can impact SPHERES
More informationTou has been released!
Tou has been released! Shoot- em-up, heavy use of collision detection Much more open-ended than previous projects Easier than previous projects if you work smart Should help those of you combating the
More informationLecture 5: Jun. 10, 2015
CMSC 132, Object-Oriented Programming II Summer 2015 Lecturer: Anwar Mamat Lecture 5: Jun. 10, 2015 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor.
More informationCMSC 313 Lecture 16 Announcement: no office hours today. Good-bye Assembly Language Programming Overview of second half on Digital Logic DigSim Demo
CMSC 33 Lecture 6 nnouncement: no office hours today. Good-bye ssembly Language Programming Overview of second half on Digital Logic DigSim Demo UMC, CMSC33, Richard Chang Good-bye ssembly
More informationPhysics 115 Future Physics Midterm Review Exam will be closed book; no calculators; no computers.
Physics 115 Future Physics Midterm Review 2016 Exam will be closed book; no calculators; no computers. You can bring a 3 x 5 index card with whatever notes and equations you want written on ONE SIDE ONLY.
More informationIntroduction to Karnaugh Maps
Introduction to Karnaugh Maps Review So far, you (the students) have been introduced to truth tables, and how to derive a Boolean circuit from them. We will do an example. Consider the truth table for
More informationLesson 12. Student Outcomes. Classwork. Opening Exercise (4 minutes) Discussion (4 minutes)
Student Outcomes Students are introduced to the formal process of solving an equation: starting from the assumption that the original equation has a solution. Students explain each step as following from
More informationNumerical solution of Nash-equilibrium Discreet version: game.r
Numerical solution of Nash-equilibrium Discreet version: game.r Lars j. Ravn-Jonsen June 2, 2009 This paper documents the program fund in game.r. for numerical game theoretic solutions of discreet games.
More information29. GREATEST COMMON FACTOR
29. GREATEST COMMON FACTOR Don t ever forget what factoring is all about! greatest common factor a motivating example: cutting three boards of different lengths into same-length pieces solving the problem:
More informationCENTRAL LIMIT THEOREM
CENTRAL LIMIT THEOREM Learning Objectives Understand the concept of the Central Limit Theorem. Understand the application of the Central Limit Theorem to increase the accuracy of measurements. How does
More informationSection 2.6 Solving Linear Inequalities
Section 2.6 Solving Linear Inequalities INTRODUCTION Solving an inequality is much like solving an equation; there are, though, some special circumstances of which you need to be aware. In solving an inequality
More informationProject # Embedded System Engineering
Project #8 18-649 Embedded System Engineering Note: Course slides shamelessly stolen from lecture All course notes Copyright 2006-2013, Philip Koopman, All Rights Reserved Announcements and Administrative
More informationBoolean circuits. Lecture Definitions
Lecture 20 Boolean circuits In this lecture we will discuss the Boolean circuit model of computation and its connection to the Turing machine model. Although the Boolean circuit model is fundamentally
More informationITI Introduction to Computing II
(with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 9, 2019 Please don t print these lecture notes unless you really need to!
More informationECE 501b Homework #4 Due: 10/22/2012
1. Game Strategy: Consider a multiplayer boardgame that takes place on the following board and with the following rules: 7 8 9 10 6 11 5 12 4 3 2 1 The board contains six squares that are property (the
More informationCS 237 Fall 2018, Homework 06 Solution
0/9/20 hw06.solution CS 237 Fall 20, Homework 06 Solution Due date: Thursday October th at :59 pm (0% off if up to 24 hours late) via Gradescope General Instructions Please complete this notebook by filling
More informationLecture 3 Probability Basics
Lecture 3 Probability Basics Thais Paiva STA 111 - Summer 2013 Term II July 3, 2013 Lecture Plan 1 Definitions of probability 2 Rules of probability 3 Conditional probability What is Probability? Probability
More informationSpeculative Parallelism in Cilk++
Speculative Parallelism in Cilk++ Ruben Perez & Gregory Malecha MIT May 11, 2010 Ruben Perez & Gregory Malecha (MIT) Speculative Parallelism in Cilk++ May 11, 2010 1 / 33 Parallelizing Embarrassingly Parallel
More informationMAIN PCB R10, 12k R31. 2) Now with the capacitors. C12,C7 C20 C6. 1N4148 D3, D5, D6 Zener 4v7 D1, D D4, D7 ferrites F1+, F2- 4) Transistors
Micrón (v.) ASSEMBLY MANUAL Thank you for choosing this kit. Let s go! WARNING: Please, read the instructions completely before start and follow the steps carefully. Some of assembly parts are not so obvious
More informationCorrelation. We don't consider one variable independent and the other dependent. Does x go up as y goes up? Does x go down as y goes up?
Comment: notes are adapted from BIOL 214/312. I. Correlation. Correlation A) Correlation is used when we want to examine the relationship of two continuous variables. We are not interested in prediction.
More informationPotential & Kinetic Energy Web Quest!
Potential & Kinetic Energy Web Quest! Introduction: You are an energy engineer employed by Energy Quest Incorporated. You will encounter several links that are provided for research and online activities.
More informationSpeed and Velocity: Recall from Calc 1: If f (t) gives the position of an object at time t, then. velocity at time t = f (t) speed at time t = f (t)
Speed and Velocity: Recall from Calc 1: If f (t) gives the position of an object at time t, then velocity at time t = f (t) speed at time t = f (t) Math 36-Multi (Sklensky) In-Class Work January 8, 013
More informationGRIDLang. Move-Driven Game Programming Language Final Report. May 10, 2017
GRIDLang Move-Driven Game Programming Language Final Report Akshay Nagpal (an2756) Parth Panchmatia (psp2137) Dhruv Shekhawat (ds3512) Sagar Damani (ssd2144) May 10, 2017 1 Contents 1 Introduction 4 2
More informationAcceleration Due to Gravity Lecture 2
Acceleration Due to Gravity Lecture 2 ˆ This lecture covers the meat of Chapters 2 and 3 from the book. I am deliberately skipping vectors again you will have to bear with me. ˆ We will cover the basics
More informationCS1083 Week 4 : Polymorphism
CS1083 Week 4 : Polymorphism Interfaces, Comparable, Searching David Bremner 2018-01-22 Interfaces Linear Search Binary Search Interfaces An interface is like a class, with all the implementation left
More informationIntroduction to Computing II (ITI 1121) FINAL EXAMINATION
Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Introduction
More informationprocess arrival time CPU burst time priority p1 0ms 25ms 3 p2 1ms 9ms 1 p3 20ms 14ms 4 p4 32ms 4ms 2
Homework #2 Solutions 1. Suppose that the following processes arrive for execution at the times indicated. Each process will run with a single burst of CPU activity (i.e., no I/O) which lasts for the listed
More informationI. Induction. Po-Shen Loh June 16, 2003
I. Induction Po-Shen Loh June 16, 2003 1 News Flash From Zuming! Remind Po to take all the markers from CBA 337 Tonight s study session for Red/Blue is in Bessey 104 Future Red lectures are in NM B-7,
More informationInterference of Light Photon with the Dark Energy
Interference of Light Photon with the Dark Energy Syed Ahmed Kataria * Integrated Child Development Service, Srinagar, India Abstract: The photon of light is constant and stable; it does not travel and
More informationIntroduction to Programming (Java) 3/12
Introduction to Programming (Java) 3/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction
More informationImpulse. Observations
Impulse Observations What is the physics behind breaking an egg? If we look at the situation in terms of force, an egg dropping seems to have the same force (of gravity) as an egg sitting on a counter,
More informationCMSC 132, Object-Oriented Programming II Summer Lecture 12
CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 12 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 12.1 Trees
More informationMI-RUB Exceptions Lecture 7
MI-RUB Exceptions Lecture 7 Pavel Strnad pavel.strnad@fel.cvut.cz Dept. of Computer Science, FEE CTU Prague, Karlovo nám. 13, 121 35 Praha, Czech Republic MI-RUB, WS 2011/12 Evropský sociální fond Praha
More informationThe Game of Cubic is NP-complete Erich Friedman Stetson University
The Game of Cubic is NP-complete Erich Friedman Stetson University efriedma@stetson.edu Introduction In the puzzle solitaire game of Cubic, there are variously colored unit blocks in some configuration.
More informationLecture notes for Analysis of Algorithms : Markov decision processes
Lecture notes for Analysis of Algorithms : Markov decision processes Lecturer: Thomas Dueholm Hansen June 6, 013 Abstract We give an introduction to infinite-horizon Markov decision processes (MDPs) with
More information