Jump to content

  • Log In with Google      Sign In   
  • Create Account


Dan Berliner

Member Since 06 Apr 2011
Offline Last Active Feb 04 2013 10:06 AM

Topics I've Started

C++ arbitrarily sorting a struct

16 December 2012 - 08:23 PM

I'm currently making a scrabble like game, the AI is the topic of this week. Basically the computer goes though and finds every possible place it can make a move. I handle this data with the below struct
[source lang="cpp"]struct Move{ int startx,starty, score, dir; std::string word;};[/source]

While the string and score are there for later reasons, any object with the same starting points and direction must be the same word. My algorithm for finding possible moves takes on duplicates so I'm using std::set to store it. To do this, however, I need a way to compare one Move from another. Dir ranges from 0-1, startx and starty both range from 0 to 15 (in theory they can be expanded, unlikely ever more than 100 though). Here is what I am currently using

[source lang="cpp"]bool operator<(const Move &a, const Move &b){ return (a.dir + a.startx*10 + a.starty*1000) < (b.dir + b.startx*10 + b.starty*1000);}[/source]

As long as the starting X position is under 100 I don't see any way to produce false-duplicates.

Is there a better way to do this?

Working with a C++ data type on a bit by bit level

06 April 2011 - 01:55 PM

I am using C++, I have no decided on a graphics library so I am open to anything that works on Windows and *nix if it makes my life easier. This is more of a theory question though so I don't think it will be relevant which one I am using.

While it is not a game, I am writing a program that allows the user to create a one color overlay over an image with a paintbrush. My first major issue is storing all that data, the program will mainly be used on projectors running at sizes as large as 1920x1080, meaning that it will use a minimum of 1.98mb of data at any given time. My issue is this: there is no one bit data type, the smallest C++ data type is 32 bits. While 1.98mb of data in memory isn't an issue at any level, having 63.4mb of data would be just inefficient. As an electrical engineer I am familiar with binary and know that each int can hold 32 pixels of data, my problem is working with an int in terms of bits.

My question is how would I discern which bits are what? I would need (for instance) the number 2800169371 to correspond to its binary value, 10100110111001110011000110011011, where 1 is on and 0 is off. I would have to go though each bit and see if it on or off.

PARTNERS