mardi 26 avril 2022

How to create a functioning card class to replicate game?

I am creating a game that looks for the best positions to insert a card in a deck of cards. I am using classes for this (OOP) but I am quite confused as to how to create this. This is what I have so far:

An input example would be a deck of cards that look like: 4 8 8 8 6 5 4 5 7 I would, for example, insert 3 at the best position in this game, which in this context would be index 7 because in this context 8 8 8 < 6 5 4 3

How would I start writing my code to demonstrate this?

p.s: It would not be best to place it in the beginning because group of adjacent cards which count by ones either up or down, weigh more in the game (i.e 3456, 5678, 1234). If placed in the beginning it would be "34"888 ... which would be of count two. Why insert at index one with a count of two when it can continue at index 7 and be "6543" a count of four paired cards?

#include <iostream>
#include <vector>
#include <map>
using namespace std;

class Hand
{
    private
        vector<int>cards;
        unsigned currentCard;
      int _hand_size;
      vector<int>_cards;
      int _insert;
   public:
        Hand(int _hand_size, vector<int>cards, int insert)
      {
          _hand_size = hand_size;
          _cards = cards;
          _insert = insert;
      }
      vector<int> get_hand()
      {
         return _cards;
      }
};

//Controls execution of program.
int main()
{
   std::string num_str = "";
   std::cin >> num_str;
   size_t hand_size = 0;
   std::cin >> hand_size;
   std::string deg_str = "";
   std::cin >> deg_str;
   vector<int> cards(hand_size);
   for (size_t index = 0; index < hand_size; index++)
   {
      std::cin >> cards[index];
   }
   for (size_t index = 0; index < hand_size; index++)
   {
   }
   std::string insert_size = "";
   std::cin >> insert_size;
   size_t insert = 0;
   std::cin >> insert;
}

Aucun commentaire:

Enregistrer un commentaire