1 / 91

Object-Oriented Programming (Java), Unit 15

Object-Oriented Programming (Java), Unit 15. Kirk Scott. Programming Project. Background Information Wari Togiz Kumalak Example Programs Assignment. Background Information. Wari and Togiz Kumalak are two different versions of the same kind of board game.

seanna
Download Presentation

Object-Oriented Programming (Java), Unit 15

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object-Oriented Programming (Java), Unit 15 Kirk Scott

  2. Programming Project • Background Information • Wari • Togiz Kumalak • Example Programs • Assignment

  3. Background Information • Wari and Togiz Kumalak are two different versions of the same kind of board game. • This section gives some historical and cultural information about these games. The next two sections describe the rules of play. • Example code for implementations of Wari is provided.

  4. Several different implementation choices are discussed. • The assignment for the unit is to implement Togiz Kumalak in Java. • It is the very last thing covered in these overheads.

  5. Wari, and games like it, have been extensively studied. • This first section of the unit contains excerpts from published works on Wari. • The first source is: Games of the World: How to Make Them, How to Play Them, How They Came to Be

  6. Wari is one of many similar board games played in various parts of the world. • They are generically known as mancala games and have been played for thousands of years in Egypt, where boards have been found carved into the stone of the pyramid of Cheops and the temples at Luxor and Karnak.

  7. The game spread to Asia and Africa, where the Arabs developed certain variations. • It thus survived through all the epochs of Egyptian history. • European travelers were introduced to it in the cafes of nineteenth century Cairo, where it was customary for the loser to pay for the coffee drunk during the game.

  8. African slaves brought mancala games to Surinam and the West Indies, where they survive unchanged. • In some rural areas of Africa today, children play these age-old games on ‘boards’ scooped out of the ground.

  9. Here is an excerpt from: Board and Table Games From Many Civilizations • It provides more historical and cultural background for games like Wari.

  10. Professor Flinders Petrie found a rough block of limestone at Memphis containing three rows of fourteen pits which appears to be an early form of Mankala’h. • The store suggests that pieces were captured and the pits are so small that the pieces were probably beans or seeds.

  11. There are several sets of deeply cut holes in the roofing slabs of the Kurna temple at Thebes, c. 1400 B.C. • Other sets of boards are cut into the summit of the damaged portion of the great pylon built in Ptolemaic times at the entrance of the temple of Karnak, and also at the Luxor temple. • The boards consist of two rows of six, seven, and eight saucer-shaped holes, the largest being 3½ in. wide and 1 in. deep.

  12. Boards have been found in Arabia dating from before the time of Muhammad, and the followers of the prophet carried variations of the game to the countries influenced by their culture. • Mancala is used as a generic noun for all the games of the Mankala’h type. • …

  13. In the New World African slaves played their native games and taught them to their children. • It is still possible to trace the ancestral origins of some West Indian Negroes by their form of mancala. • Four variants of Wari are found among the Negroes of Guiana and the Caribbean which match with the games of Dahomey, Togoland, and Nigeria.

  14. The games have several names, one being Awari. • As an intellectual exercies it is on a level with chess. • The Negroes play for amusement and the prestige accruing to a good player. • They will not play for money.

  15. Finally, here is an excerpt from: The Oxford History of Board Games • It provides more background information:

  16. Mancala is probably of Black African origin, and Culin rightly characterizes it as Africa’s national board game. • There is, however, no universally accepted ‘official’ or ‘standard’ version. • On the contrary, it is a typical folk game—the ludic equivalent of a series of mutually intelligible dialects each of which is standard only for its own locality.

  17. Any given variety may have several different names within a single gaming community; • conversely, the same name, or variants of it, will often denote a number of different but similar games. • Playing Mancala is as generic an activity as playing cards. • …

  18. Mancala is a game of perfect information, perfect equality, much freedom of significant choice, and hence great skill. • Westerners will assume at first sight that one player, probably the first to move, has a certain win or at least a draw, and that the play will be slow and drawn-out as each in turn considers every possible move and as many branches down the resultant strategy tree as the human brain can manage.

  19. It is obviously ideal for computer analysis, and researches along this line suggest that a complete solution is imminent. • Some might eschew Mancala on the ground that it lacks, on one hand, the random elements of Bridge and Backgammon which render them amenable to intuitive play, and, on the other, the two-dimensional structure of Chess which poses more of a challenge to intellectual analysis.

  20. The complexity of Chess lies in its depth, that of Mancala in its length. • What the westerner tends to ignore, however, is the value of games as a form of social bonding and mental recreation. • In fact, native practitioners of Mancala play at surprising speed, and experts with deadly accuracy.

  21. Even without counting the contents of the most heavily loaded holes, many have a knack of unerringly selecting the best line of play from what appears to be the benefit of intuition derived from experience. • To play at the sloth of Chess is to miss the point of the game.

  22. As our epigraph shows, the play of Mancala, at least in Africa, is a social activity, to which bystanders contribute so substantially that it is sometimes impossible to distinguish players from kibitzers. • Some of the larger and more elaborate games are indeed played by two teams commanding either side of a particularly long board.

  23. Against this background, however, Lenox-Smith regretfully notes that ‘cultured’ West Africans nowadays tend to regard Mancala as a game for children and peasants, and that some of the boards commercially available in large towns are of the wrong size or feel, suggesting that their producers have lost touch with their cultural roots.

  24. This will be recognized as a well-known social phenomenon in any country dominated by one (in this case ‘The West’) whose culture is perceived as more advantageous and hence more worthy of emulation.

  25. Wari • The board for Wari consists of two rows of six cups each, one row for each player. • These cups are initially filled with four seeds apiece. • Each player also has a separate cup for winnings, which starts out empty. • A representation of the initial state of the board and cups is shown below.

  26. The basic rules of Wari: • As a player, you pick up the contents of one of the cups on your side of the board. • You then go counterclockwise around the board, starting with the cup immediately after the one you emptied, dropping one seed at a time into each succeeding cup until there are none left to drop. • If the last seed dropped goes into one of your opponent’s cups which contains only one or two seeds, this is your win. • You get to take the two or three seeds which result, and put them into your winnings cup.

  27. After you finish one play, whether you win any seeds or not, it is then your opponent’s turn. • The game continues until one player has no seeds left to play. • If you are the player with seeds left on your side of the board, you get to add them to your winnings. • The winner of the game is the player with the highest winnings.

  28. Togiz Kumalak • The Togiz Kumalak game board is shown on the next page. • Following the board, the rules of play are given. • The board for Togiz Kumalak consists of two rows of nine cups each, one row for each player. • These cups are initially filled with nine seeds apiece.

  29. Player 1’s side is on top and player 2’s side is on the bottom. • Each player also has a separate cup for winnings, which starts out empty. • The winnings cups are in the center of the board. • A representation of the initial state of the board and cups is shown below.

  30. Player 2’s winnings go in this area. They are taken from player 1’s cups, which are on this side of the board. Player 1’s winnings go in this area. They are taken from player 2’s cups, which are on this side of the board.

  31. The basic rules of Togiz Kumalak: • Players take turns, and on each turn, you as a player can pick up the seeds from any cup on your side that has some in it. • If there is only one seed in a cup, you pick that one up. • If there is more than one seed, then you pick up all but one. • You then drop the seeds one-by-one in each cup, moving counterclockwise around the board.

  32. The basic rules of Togiz Kumalak, continued: • If a cup has an even number of seeds in it, it is referred to as closed. • If it has an odd number in it, it is referred to as open. • If the last seed you drop is into one of your opponent’s cups which is open, you win all of the seeds in that cup. • The overall strategy of play is to open your opponent’s cups by leaving an odd count in them, and to close your own by leaving an even count in them.

  33. The basic rules of Togiz Kumalak, continued: • If the last seed on a play is dropped into one of your opponent’s cups with 2 seeds in it, this cup becomes what is referred to as your home on the opponent’s side of the board. • You immediately win the 3 seeds in that cup and for all following play, any seed that goes into that cup, whether one played by you or your opponent, goes into your winnings. • A player can only have one home, so after getting one, the usual rules apply to cups with 2 seeds in them--They are cups with an even count.

  34. Both players can have a home. • The fact that one player has one doesn’t prevent the other from getting one. • On a physical board, a cup that has become a home is usually marked with a special game piece that is different from the regular ones.

  35. The basic rules of Togiz Kumalak, continued: • Play ends when one player runs out of seeds on his side of the board. • When this happens the player with seeds remaining gets to add them to his winnings. • The player with the most seeds wins.

  36. Example programs: • WariV1 • WariV21 • WariV22

  37. WariV1 • A screenshot of WariV1 is shown on the next overhead. • It uses the MyTerminalIO class to do I/O. • This means that it produces a little dialog box when you call getInt(), getDouble(), or getString() for input. • It also means that a call to println() puts ASCII text output into a graphical window. • It does not use the System.out.println() black screen of death, although that would be an option.

  38. WariV1 • This is a simple program consisting of a single class in one file. • The code follows.

  39. public class WariV1 • { • public static void main(String[] args) • { • /* Declarations */ • int[][] gameboard = new int[2][6]; • int[] captured = new int[2]; • int handfull; • int whoseturn = 0; • int chosencup; • int currentcup; • int currentside; • boolean goagain = true; • String answer; • int i; • int j;

  40. /* This is needed for I/O. */ • MyTerminalIO myterminal = new MyTerminalIO(); • /* Array initializations */ • for(i = 0; i <= 1; i++) • { • captured[i] = 0; • for(j = 0; j <= 5; j++) • { • gameboard[i][j] = 4; • } • }

  41. /* Display the game board. Note that player 0's side is printed "backwards". The board is shown from player 1's perspective. From this point of view, to display player 0's cups correctly, you have to count down from left to right rather than up. The game board is displayed again below. A little more thought about the placement of things in the loop would probably result in an arrangement where this code doesn't have to appear twice. However, this is the inspiration of the moment and it works. */ • myterminal.println("Player 0, captured " + captured[0] + "\n"); • for(j = 5; j >= 0; j--) • { • myterminal.print(" " + gameboard[0][j]); • if(gameboard[0][j] < 10) • myterminal.print(" "); • if(j >0) • myterminal.print(" |"); • } • myterminal.println("\n-----------------------------"); • for(j = 0; j <= 5; j++) • { • myterminal.print(" " + gameboard[1][j]); • if(gameboard[1][j] < 10) • myterminal.print(" "); • if(j < 5) • myterminal.print(" |"); • } • myterminal.println("\n\nPlayer 1, captured " + captured[1] + "\n\n");

  42. /* As long as the players want to play, continue the game. • This version of the code does not determine when the game is • over or who the winner is. The human players have to do that. */ • while(goagain) • { • /* Now prompt for for whoseturn's move. */ • /* This is the way you call the myterminal method for • reading an int. */ • chosencup = myterminal.getInt("\nIt is player " + whoseturn • + "'s move.\nPlease enter the number, from 1 to 6,\n • of the cup you want to play: "); • chosencup--; • myterminal.println(); • /* Now pick up the seeds from the cup and prepare to play. */ • currentcup = chosencup; • currentside = whoseturn; • handfull = gameboard[currentside][chosencup]; • gameboard[currentside][chosencup] = 0;

  43. /* Play the pieces. */ • while(handfull != 0) • { • /* Move to the next cup. Notice how you cycle through the array, switching from • one side of the board to the other. */ • currentcup = (currentcup + 1) % 6; • if(currentcup == 0) • currentside = 1 - currentside; • /* Drop a seed. */ • gameboard[currentside][currentcup] += 1; • handfull--; • /* Capture. */ • if(currentside != whoseturn && (gameboard[currentside][currentcup] == 2 • || gameboard[currentside][currentcup] == 3)) • { • captured[whoseturn] += gameboard[currentside][currentcup]; • gameboard[currentside][currentcup] = 0; • } • }

  44. /* Display the game board again. */ • myterminal.println("\n\nPlayer 0, captured " + captured[0] + "\n"); • for(j = 5; j >= 0; j--) • { • myterminal.print(" " + gameboard[0][j]); • if(gameboard[0][j] < 10) • myterminal.print(" "); • if(j >0) • myterminal.print(" |"); • } • myterminal.println("\n-----------------------------"); • for(j = 0; j <= 5; j++) • { • myterminal.print(" " + gameboard[1][j]); • if(gameboard[1][j] < 10) • myterminal.print(" "); • if(j < 5) • myterminal.print(" |"); • } • myterminal.println("\n\nPlayer 1, captured " + captured[1] + "\n\n");

  45. /* One player's move has come to an end • and it's the other player's turn. */ • whoseturn = 1 - whoseturn; • answer = myterminal.getString("\nEnter 'no‘ • to quit.\nAny other input will continue • play: "); • if(answer.equals("no")) • goagain = false; • } • } • }

  46. WariV21 • This is a program consisting of multiple classes saved in multiple files. • Its appearance is the same as WariV1. • The code for it follows.

  47. /** • This is the program file/Class for the second wari programming • assignment, the one using classes and objects. • @author Kirk Scott • @version 21 • */ • public class WariV21 • { • public static void main(String[] args) • { • MyTerminalIO myterminal = new MyTerminalIO(); • int playTurn = 1; • int playCup = 1; • boolean playAgain = true; • String answer = null; • BoardV21 playBoard = new BoardV21(); • playBoard.showBoard(myterminal);

  48. while(playAgain == true) • { • playCup = myterminal.getInt("\nIt is player " + • playTurn + "'s move.\nPlease enter the number, • from 1 to 6,\nof the cup you want to play: "); • playBoard.moveBoard(playTurn, playCup); • playBoard.showBoard(myterminal); • if(playTurn == 1) • playTurn = 2; • else • playTurn = 1; • answer = myterminal.getString("\nEnter 'no' to • quit.\nAny other input will continue play: "); • if(answer.equals("no")) • playAgain = false; • } • } • }

More Related