一个用C语言修改过的Nim游戏?

一个用c语言修改过的nim游戏?

Modified game of Nim is an optimisation games of arrays. This game predicts the winner based on the starting player and optimal moves.

Game Logic − In this game, we are given an array{}, that contains elements. There are generally two players that play the game namly player1 and player2. The aim of both is to make sure that all their numbers are removed from the array. Now, player1 has to remove all the numbers that are divisible by 3 and the player2 has to remove all the numbers that are divisible by 5. The aim is to make sure that they remove all elements optimally and find the winner in this case.

Sample

Array : {1,5, 75,2,65,7,25,6}Winner : playerB.A removes 75 -> B removes 5 -> A removes 6 -> B removes 65 -> No moves for A, B wins.

Code Preview

The code will find the number of elements that A can remove , number of elements that B can remove and the number of elements that they both can remove. Based on the number of the elements they both can remove the solution is found. As A removes first elements it can win even if he has to remove one element more than B. In normal case, the player with the maximum number of elements to remove wins.

PROGRAM TO FIND THE SOLUTION FOR GAME OF NIM

#include using namespace std;int main() {   int arr[] = {1,5, 75,2,65,7,25,6};   int n = sizeof(arr) / sizeof(arr[0]);   int movesA = 0, movesB = 0, movesBoth = 0;   for (int i = 0; i  movesB)         cout<<"Player 1 is the Winner";      cout< movesB)      cout<<"Player 1 is the Winner";   cout<<"Player 2 is the Winner"; ;   return 0;}

输出

Player 2 is the Winner

以上就是一个用C语言修改过的Nim游戏?的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1444224.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年12月17日 21:13:00
下一篇 2025年12月12日 15:30:51

相关推荐

  • Python游戏开发入门 Python游戏编程基础框架介绍

    #%#$#%@%@%$#%$#%#%#$%@_23eeeb4347bdd26bfc++6b7ee9a3b755dd适合游戏开发吗?适合入门但不适合大型3a游戏。python语法简单适合新手,pygame等库可做2d小游戏,但性能不如c++或c#。常用库包括pygame(文档丰富)、arcade(ap…

    2025年12月14日
    000
  • PHP游戏编程:基础图形渲染

    php可以用于游戏编程,但需结合前端技术实现图形渲染。1. php负责处理游戏逻辑、数据存储和用户交互;2. 图形渲染依赖html5 canvas或webgl;3. 用户输入通过表单或ajax发送至php处理并更新游戏状态;4. 性能优化包括减少网络传输、使用opcode缓存、高效算法及前端渲染优化…

    2025年12月11日 好文分享
    100

发表回复

登录后才能评论
关注微信