Questions tagged [nim-game]

Nim is a two-player strategy game. Each turn, the player chooses a heap and removes various items from it. When all heaps are empty there is no possible move, and the player loses.

Use this tag for questions that about algorithms and other programming problems specifically related to playing the Nim strategy game. Do not use this tag for games written in the (formerly known as "Nimrod") programming language.

External links

17 questions
8
votes
3 answers

Tower Breakers - nim game variation with divisors

I have encountered a game called Tower Breakers, which seems a variation of the nim game. There are two players, player 1 and player 2. Initially there are n towers, where each tower is of height m, both n and m positive integers. Player 1 begins,…
Oriol
  • 274,082
  • 63
  • 437
  • 513
2
votes
2 answers

Weighted Nim with Stacks instead of piles and each player picks from opposite sides

There n stacks of coins. Each stack contains k_i coins and the coins in a particular stack have distinct values. In each turn, you get to pick one coin from the top of any stack, and your opponent can pick one coin from the bottom of any stack. The…
1
vote
0 answers

MiniMax algorithm in Kotlin - Nim Game

I have a question regarding my implementation of the minimax algorithm for the game called "nim game" in kotlin. It is based on the minimax algorithm that is described in wikipedia. I do not really know why it is not working. I think the problem is…
1
vote
1 answer

21 counting game (like nim game)

I'd like to develop a bot that is able to win the 21 - counting game/NIM - game every time. Rules: Here are the rules for the game: In a game players take it in turns to say up to 3 numbers (starting at 1 and working their way up). Who every say's…
user3596335
1
vote
2 answers

Choosing the Best Matrix

I am given X matrices of size Ni*Mi where 1<=N<=4 and 1<=M<=4, for all 1 <= i <= X The game consists of choosing any rectangle (submatrix) from one of the given X matrices and removing this submatrix. For Example: we have 1 matrix of size 4x4.…
Narendra Modi
  • 851
  • 1
  • 13
  • 29
0
votes
0 answers

Minimax Algorithm Issue in Nim Game AI - Opponent Always Choosing 1 Matchstick

I'm working on implementing an AI opponent using the Minimax algorithm for the well-known game of "Nim", which is a two-player game where each player takes turns removing 1 to 3 matchsticks from a pile. The player who removes the last matchstick…
dya47
  • 11
  • 2
0
votes
0 answers

Writing a program of nim game with python

How do I write a program with multiple functions that makes the outcome look like the following: Let's play NIM! NIM_State {a:10, b:10, c:10} your move: b 10 removing 10 from b gives NIM State {a:10, b:0, c:10} computer move: c 5 removing 5 from c…
0
votes
1 answer

How to remove the last child from a certain div of a div

I'm crawling the last steps towards a project assigned for one of my classes. Basically, I have to create an implementation on web of the NIM game only using HTML/CCS/JavaScript. Tomorrow's the deadline and I'm almost done, I just have an error on…
0
votes
1 answer

Number of stones is inconsistent, nim game

The issue is that the number of stones the computer takes differs from the number that is displayed on the screen. I know it's cause the function is being repeated twice. But I can't find a way to store the random number generated and use that…
Soda
  • 3
  • 3
0
votes
0 answers

How to do looping in this Java game?

I am a college student just learning the basics of programming in Java. I was given the task of recreating the game of NIM playing against a computer. The rules I was given where that there are 3 piles of 10, you can remove any amount from one pile…
Marcus
  • 11
  • 2
0
votes
1 answer

How to reduce values in list using user input and printing updated list

So I am trying to build a NIM game. I got stuck with the reducing from the list and printing out an updated list instead: #reduces from board-list def reducer(choice_1, choice_2,board): if choice_1 == 'a': board[0] - int(choice_2) …
0
votes
2 answers

How to achieve a value in recursion function?

I have tried to program minimax nim game with Python. I am almost done with the codes. However, I could not solve a problem, which is so tricky. I could not reach 'best movement' of the algorithm. I started with (5, Max) position and the algorithm…
Vural Erdogan
  • 101
  • 12
0
votes
2 answers

How do i limit the user to only inputting 1-3

import java.util.Random; import java.io.*; import java.util.*; /** Courtney Fox Professor Yao Midterm Part 1 10/10/17 Purpose: The purpose of this program is to develop a Nim game that consists of a pile of stones…
0
votes
2 answers

How to use Manhattan Distance to solve this game?

Each player takes turns, removing 1 or 2 bananas from a basket of 50 bananas. The player who empties the basket wins. What are the weights that should be used for the distances, and what should the matrix size be? Should the matrix change every time…
0
votes
1 answer

Grundy Number For a Matrix

How to calculate the Grundy number for states of a 4*4 matrix. A valid move consists of transforming the 1s into 0s of a submatrix having all 1s. Example: 1010 0011 0000 0000 Grundy Number = 2 I checked for smaller cases and calculated the Grundy…
Deepak
  • 45
  • 1
  • 8
1
2