title: Pick Up Sticks / Intelligent AI / Python
body: <p><strong>BACKGROUND INFO, DON'T HAVE TO READ IF YOU'D JUST LIKE TO VIEW THE PROBLEM WITH CODE BELOW:</strong></p>
  
  <p>I hope everyone is familiar with the game of sticks or "nim." If not, you set a starting amount of sticks (between 10 and 50) and draw (1-3 sticks) until there aren't any sticks left, declaring the one who pulled the last stick the loser. In my programming class we've also included the option of playing against the AI. But, the AI is no longer a dummy who randomly picks a number 1-3. Now he learns from each of his turns.</p>
  
  <p><strong>Implementation</strong>:</p>
  
  <ul>
  <li><p>The AI has a bucket for each of the number of sticks left. There is a bucket for 1 stick 
  left, 2 sticks, 3 sticks, etc.</p></li>
  <li><p>At the beginning of the game each bucket has 3 balls in it. Each marked with the choice 
  1, 2 or 3. These represent the AI’s choice of picking up 1, 2 or 3 sticks. </p></li>
  <li>During the AI’s turn, it takes a random ball from the bucket representing the number of 
  sticks left. It reads the ball and removes that number of sticks from the pile. It then 
  places the ball in front of the bucket.</li>
  <li>If the AI wins the game, then it goes through all of its choices and puts two balls back for 
  the chosen number for each choice it made. Increasing its chances of choosing that ball 
  the next time it’s faced with a choice with the given number of sticks.</li>
  <li>If the AI loses, then it throws the ball away next to the buckets. However, if the chosen 
  ball is the last choice then it puts it back into the bucket. The bucket must contain at 
  least one of each number. So if the user chose a ball that had a number of sticks to 
  pick from a bucket, and it was the last ball of that choice, then if the AI loses, it must put 
  that ball back. It can never remove any of the choices completely from the buckets.</li>
  <li>As more games are played the AI will reinforce good choices with extra balls for winning 
  sticks picked up."</li>
  </ul>
  
  <p>Here's the code I'm working with right now. </p>
  
  <pre><code>choice=random.randint(1,maxchoice) #computer picks a random number
  bucketnum=sticks #bucket to take ball from
  pullnum=choice #ball to take 
  for i in bucket:
      for bucket[bucketnum] in i:
          bucketnum.pop(pullnum)
      print(bucket[bucketnum])
  </code></pre>
  
  <p>The bucket that I'd be taking the ball out of would essentially be the number of sticks left, I'm just having trouble finding a specific bucket in the bucket list and taking out the ball. Right now I get an error message saying that bucketnum.pop(pullnum) - 'int' object has no attribute to 'pop'? This is the bucket code (lists within a list):</p>
  
  <pre><code>bucket=[]
  for j in range(51):
      bucket.append([1,2,3])
  </code></pre>
  
  <p>I may be totally confusing but if anybody has any advice or even questions for clarification, please do reply. Thanks all.</p>
  
  <p><strong>EDIT:</strong>
  Here's some more code, sorry, stupid of me to refrain from adding the definitions of variables, etc.</p>
  
  <pre><code>            if option==2:
              sticks=""
              while True:
                      try:
                          sticks=int(input("Enter the number of sticks to begin with: "))
                          if sticks&gt;=10 and sticks&lt;=50:
                              print("Alright, there are",sticks,"sticks in the pile.")
                              break
                          else:
                              print("You mut enter an integer. (10-50)")
                      except ValueError:
                          print("You must enter an integer.")
              player1=True
              while sticks&gt;0:
                  maxchoice=min(3,sticks)
                  choice=-1
                  countbucket=0
                  if player1:
                      while choice&lt;1 or choice&gt;maxchoice:                           
                          try:
                              choice=int(input("Player 1, how many sticks would you like to take? (1-3): "))
                              if choice&gt;=1 and choice&lt;=3:
                                  sticks-=choice
                                  print("There are",sticks,"sticks remaining.")
                              else:
                                  print("You must enter an integer from 1-3.")
                          except ValueError:
                              print("You must enter an integer.")
                      player1=not player1
                  else:
                      choice=random.randint(1,maxchoice)
                      bucketnum=sticks
                      pullnum=choice
                      for i in bucket:
                          for bucket[bucketnum] in i:
                              bucketnum.pop(pullnum)
                          print(bucket[bucketnum])
                      sticks-=1
                      print("Computer drew",choice,"stick(s). There are",sticks,"sticks remaining.")
                      player1=not player1
              if player1==False:
                  print("Player 1 took the last stick.\nComputer wins!")
              else:
                  print("Player 1 wins!")
  </code></pre>
  
  <p>This is option 2 in my program, as option 1 is Player 1 vs. Player 2. Obviously I haven't gotten very far with the implementation of the AI intelligence, it's a bit tricky.</p>
  
  <p>-----> Fred S., I'm just getting started and having issues getting the mental wheel spinning. What's excerpted isn't all of the code. I'm not asking how to complete the assignment at this point, though tips on executing this new intelligent AI code would be helpful, but in this case it's more a focus on figuring out list indexing. </p>