Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Just one other idea Mancala

The rules and a picture of the board are given here: http://www.centralconnector.com/GAMES/mancala.html

If you are not familiar with the game, try it before you pooh-pooh it as too simple. The programming logic should be fairly straight forward, but still challenging and the player needs to play a clever strategy. It is more complex and unique than tic tac toe.

Advantages as a Science fair project it can be designed and developed in stages, any of the stages would be acceptable as a project for the fair submission.

Possible steps:
1)board lay out can be in non graphic mode, using digits to represent the number of stones in each bowl. With dashes or * as separators.
2) programming can be done as a series of variables, or as an array to calculate the move results handled in either for, or while loops.
3) user input can be designated as a text entry designating the bowl whose stones should be distributed.
4) the gui representation can be added later if time permits.

Good luck to your sister in the project!

And I bet you could point her to a super place to get perl advice!

Update - here is some crude code - it uses arrays and simple control statements to create a text mancala board, allows a user to enter a bin number and then distributes the stones. Please note there are much more elegant ways to handle the situation, but I tried to keep the code concepts fairly basic so a new user could get a feel for it wihout being overwhelmed. I assume you will be helping/coaching your sister.

I would strongly suggest you and your sister play the game in the real world, to get a feel for where the code should go.

this code was developed in the following order:
1) create 2 arrays, display the board.
2) accept user input, and edit check it.
3) distribute stones code
#### don't panic this code is not complex, just repetitive

Nuff said, I hope this code may help as an idea generator.

#!/usr/bin/perl # this program creates a text based maa board with text input ######################################### ########### DON'T PANIC ######################################### # bins for each player (should be 7 - 6 bins + 1 mancala) @p1 = (4,4,4,4,4,4,0); @p2 = (4,4,4,4,4,4,0); while ($in ne "Q"){ # send the routine to draw the board the number of stones in each bin &draw_board($p1[0],$p1[1],$p1[2],$p1[3],$p1[4],$p1[5],$p1[6], $p2[0],$p2[1],$p2[2],$p2[3],$p2[4],$p2[5],$p2[6]); # ask for input print "enter bin to distribute or Q to exit:"; # get keyboard input $in = <>; # remove the carriage return from the entry chomp $in; # edit check the input # return to top of loop if Q is entered next if ($in eq "Q"); # display error message if a non digit or bin number is out of range # then erturn to the top of the loop if ($in =~ /\D/ || $in < 1 || $in > 12){ print " bin can only be 1 through 12 or Q\n\n"; next; } # we have a valid entry, so distribute stones &distribute_stones($in); } sub distribute_stones{ # set variable $bin to the user input bin t be distribuetd $bin = $_[0]; # set the variable $stones_2_distribute equal to the number of stones # in the array for player 1 or player 2 represented by the bin number # the user entered. Then set that array entry to 0. (because all of # the stones in that bin have been picked up to be distributed) # # remember - perl arrays are indexed from 0 - or simply stated, the # first entry used in a per array is number 0. # this code is for the player 1 array (@p1) if ($bin == 1){ $stones_2_dist = $p1[0]; $p1[0] = 0; } if ($bin == 2){ $stones_2_dist = $p1[1]; $p1[1] = 0; } if ($bin == 3){ $stones_2_dist = $p1[2]; $p1[2] = 0; } if ($bin == 4){ $stones_2_dist = $p1[3]; $p1[3] = 0; } if ($bin == 5){ $stones_2_dist = $p1[4]; $p1[4] = 0; } if ($bin == 6){ $stones_2_dist = $p1[5]; $p1[5] = 0; } # this code is for player 2 array (@p2) if ($bin == 7){ $stones_2_dist = $p2[0]; $p2[0] = 0; } if ($bin == 8){ $stones_2_dist = $p2[1]; $p2[1] = 0; } if ($bin == 9){ $stones_2_dist = $p2[2]; $p2[2] = 0; } if ($bin == 10){ $stones_2_dist = $p2[3]; $p2[3] = 0; } if ($bin == 11){ $stones_2_dist = $p2[4]; $p2[4] = 0; } if ($bin == 12){ $stones_2_dist = $p2[5]; $p2[5] = 0; } # variable $bin_switch will help us determine where # to start distributing stones, then will be set to 0 # so the remaining stones can be distributed in order # $bin_switch = $bin; while ($stones_2_dist > 0){ # please see coding notes below # this piece of code will only be accessed when stone distribution # comes around the corner - it will never be the first bin a # stone is distributed to if ($bin_switch < 1){ $p1[0]++; $stones_2_dist--; $bin_switch = 0; } next if ($stones_2_dist < 1); if ($bin_switch < 2){ # add 1 to player 1 array first entry # the folloing line is shorthand for $p1[0] = $p1[0] + 1 $p1[1]++; $stones_2_dist--; # subtract one from our pile of stones to dis +tribute $bin_switch = 0; # set the bin switch to zero so remainder of st +ones can be distribnuted } # this line will cause control to return to the top of the # loop, if there are no more stones to distribute, where # the while statement will terminate the loop next if ($stones_2_dist < 1); if ($bin_switch < 3){ $p1[2]++; $stones_2_dist--; $bin_switch = 0; } next if ($stones_2_dist < 1); if ($bin_switch < 4){ $p1[3]++; $stones_2_dist--; $bin_switch = 0; } next if ($stones_2_dist < 1); if ($bin_switch < 5){ $p1[4]++; $stones_2_dist--; $bin_switch = 0; } next if ($stones_2_dist < 1); if ($bin_switch < 6){ $p1[5]++; $stones_2_dist--; $bin_switch = 0; } next if ($stones_2_dist < 1); #determine if a stone should be dropped in player 1's #mancala (bins 1-6 belong to player 1) if ($bin > 0 && $bin <7){ $p1[6]++; $stones_2_dist--; $bin_switch = 0; } next if ($stones_2_dist < 1); ## begin player 2 array # this piece of code will only be accessed when stone distribution # comes around the corner - it will never be the first bin a # stone is distributed to if ($bin_switch < 7){ $p2[0]++; $stones_2_dist--; $bin_switch = 0; } next if ($stones_2_dist < 1); if ($bin_switch < 8){ $p2[1]++; $stones_2_dist--; $bin_switch = 0; } next if ($stones_2_dist < 1); if ($bin_switch < 9){ $p2[2]++; $stones_2_dist--; $bin_switch = 0; } next if ($stones_2_dist < 1); if ($bin_switch < 10){ $p2[3]++; $stones_2_dist--; $bin_switch = 0; } next if ($stones_2_dist < 1); if ($bin_switch < 11){ $p2[4]++; $stones_2_dist--; $bin_switch = 0; } next if ($stones_2_dist < 1); if ($bin_switch < 12){ $p2[5]++; $stones_2_dist--; $bin_switch = 0; } next if ($stones_2_dist < 1); #determine if a stone should be dropped in player 2's #mancala (bins 7-12 belong to player 2) if ($bin > 6 && $bin <13){ $p2[6]++; $stones_2_dist--; $bin_switch = 0; } # the following line is not technically required # but will save trouble if you ever need to add # some code between this line and the end of the loop next if ($stones_2_dist < 1); } } sub draw_board{ # display the board print "\n\n\n"; printf " Bin=| %3d | %3d | %3d | %3d | %3d | %3d | \n\n" ,12,11, +10,9,8,7; printf "-------------------------------------------------\n"; printf " %3d | %3d | %3d | %3d | %3d | %3d | %3d | \n" ,$_[13],$ +_[12], $_[11],$_[10],$_[9],$_[8],$_[7]; printf " |-----+-----+-----+-----+-----+-----| \n"; printf " | %3d | %3d | %3d | %3d | %3d | %3d | %3d\n" ,$_[0], +$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]; printf "-------------------------------------------------\n"; printf "\n Bin=| %3d | %3d | %3d | %3d | %3d | %3d | \n\n" ,1,2, +3,4,5,6; }

Enjoy!
Dageek


In reply to Re: [OT] Perl / Computer Science Science Fair Projects by johndageek
in thread [OT] Perl / Computer Science Science Fair Projects by amarquis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (8)
    As of 2014-12-26 05:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (165 votes), past polls