1 / 98

Object-Oriented Programming (Java), Unit 16

Object-Oriented Programming (Java), Unit 16. 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.

vivi
Download Presentation

Object-Oriented Programming (Java), Unit 16

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 16 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. Flinders Petrie • From Wikipedia, the free encyclopedia • William Matthew Flinders PetrieFRS[2] (3 June 1853 – 28 July 1942), commonly known as Flinders Petrie, was an English Egyptologist and a pioneer of systematic methodology in archaeology and preservation of artifacts. He held the first chair of Egyptology in the United Kingdom, and excavated at many of the most important archaeological sites in Egypt, such as Naukratis, Tanis, Abydos and Amarna. Some consider his most famous discovery to be that of the Merneptah Stele,[3] an opinion with which Petrie himself concurred.[4]

  12. Merneptah Stele • From Wikipedia, the free encyclopedia • The Merneptah Stele—also known as the Israel Stele or Victory Stele of Merneptah—is an inscription by the Ancient EgyptiankingMerneptah (reign:1213 to 1203 BC), which appears on the reverse side of a granite stele erected by the kingAmenhotep III. It was discovered by Flinders Petrie in 1896 at Thebes. • The stele is notable for being the only Ancient Egyptian document generally accepted as mentioning "Isrir" or "Israel". It is the earliest known attestation of the demonymIsraelite. It is therefore referred to it as the "Israel stele".

  13. 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.

  14. 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. • …

  15. 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.

  16. 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.

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

  18. 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.

  19. 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. • …

  20. 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.

  21. 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.

  22. 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.

  23. 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.

  24. 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.

  25. 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.

  26. 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.

  27. 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.

  28. 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.

  29. 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.

  30. 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.

  31. 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.

  32. 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.

  33. 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.

  34. 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.

  35. 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.

  36. 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.

  37. 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.

  38. Example programs: • WariV1 • WariV21 • WariV22

  39. 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.

  40. WariV1 • This is a simple program consisting of a single class in one file. • A UML diagram is given on the next overhead, with the code on the following overheads.

  41. 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;

  42. /* 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; • } • }

  43. /* 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");

  44. /* 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;

  45. /* 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; • } • }

More Related