মডিফাইড নিম গেম হল অ্যারে-ভিত্তিক একটি অপ্টিমাইজেশন গেম। এটি শুরুর খেলোয়াড় এবং সর্বোত্তম মুভের উপর ভিত্তি করে বিজয়ী ভবিষ্যদ্বাণী করে।
গেম লজিক - একটি অ্যারে দেওয়া থাকে। দুটি খেলোয়াড়: প্লেয়ার ১ (৩ দ্বারা বিভাজ্য সংখ্যা সরাবে) এবং প্লেয়ার ২ (৫ দ্বারা বিভাজ্য সংখ্যা সরাবে)। উভয়ই সর্বোত্তম চেষ্টা করে নিজেদের সংখ্যা সরিয়ে বিজয়ী হতে চায়।
নমুনা
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.কোড প্রিভিউ
কোডটি A এবং B যারা কতগুলো উপাদান সরাতে পারে এবং উভয় কতগুলো সরাতে পারে তা গণনা করে। যেহেতু A প্রথমে খেলে, সে একটাই বেশি সরালেও জিততে পারে। সাধারণত যিনি বেশি উপাদান সরাতে পারেন তিনি জয়ী।
নিম গেম সমাধান প্রোগ্রাম
#include <bits/stdc++.h> 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 < n; i++) { if (arr[i] % 3 == 0 && arr[i] % 5 == 0) movesBoth++; else if (arr[i] % 3 == 0) movesA++; else if (arr[i] % 5 == 0) movesB++; } if (movesBoth == 0) { if (movesA > movesB) cout<<"Player 1 is the Winner"; cout<<"Player 2 is the Winner"; } if (movesA + 1 > movesB) cout<<"Player 1 is the Winner"; cout<<"Player 2 is the Winner"; ; return 0; }আউটপুট
Player 2 is the Winner