• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
AlluMihu

Storing hashes as game states

7 posts in this topic

Hi guys, is it a good idea to store hashes in a database as game states? Let's say I have a chess game, and a colomn of my database stores things like 1A1B1C... and each pair represents the position of some piece (first pair(1A) represents the position of 1st rock, second pair- position of the king etc...). I've read that Guild Wars uses databases as I said and every player in the game is a bunch of data stored in hashes. I know that a lot of developers use sockets, but I find it easier using a database to store states. Can you tell me the advantages and the disadvantages? Thank you.

0

Share this post


Link to post
Share on other sites

Ok, I misused hashes, because I thought you can get the original data back. Still, I think the example explains pretty well what I wanted to say. 

 

Consider two players playing chess online, on a website. The game starts and player one(A) plays with white, his colomn that stores his pieces positions (in the database) is like this 1A1B1C1D1E1F1G1H2A2B2C2D2E2F2G2H. second player(B) plays with black pieces, his colomn is like this 8A8B8C8D8E8F8G8H7A7B7C7D7E7F7G7H. Let's say A moves his first(from left to right) horse to 3A, his column will be updated and it will be like this 1A3A1C1D1E1F1G1H2A2B2C2D2E2F2G2H (notice the 1B -> 3A). The two strings that I wrote will be always initialized with 1A1B1C1D1E1F1G1H2A2B2C2D2E2F2G2H and 8A8B8C8D8E8F8G8H7A7B7C7D7E7F7G7H, based on the players color. These strings are the gamestates that I refered to, because based on them, the pieces are printed on the screen.

 

Sorry for not being explicit enought, I hope you'll understand now, here's a chess table:

is_chess.jpg

0

Share this post


Link to post
Share on other sites

Yes, that's a totally fine way to serialize the board state of a game of chess. I'm assuming that when pieces leave the board, you'll mark their slots with something like "**" instead of a board position. You can also concatenate both of the strings into a long string; you don't need to separate each of the players' states into separate strings.

To support queen promotion to more than one queen, you may need to also store state for which pieces are now "queens." This is necessary to render the board correctly, so it's part of "board state." Additionally, you need to store state for whether each player has castled or not (because you can only castle once,) and which pawns have moved two spaces (because of enpassant capture.) These states are NOT visible on the board, and are thus only GAME state, not BOARD state, so they are important to enforce rules but not render the board.

Finally, "sockets" and "databases" are totally different. "Sockets" are how remote players get messages. "Databases" are how you store persistent state so it stays around if the server reboots. All network traffic, no matter what the layer (UDP, ping, HTTPS, SSH, VoIP, ...) uses sockets as the programming API. When a player connects to your web server, that's a socket. When your web server makes a query to a database, that's typically also a socket connection, over which the persisted database data is transferred.

2

Share this post


Link to post
Share on other sites

I would use a 2D array, because the way you're doing it it seems like you'd have to sent that entire string back and forth ? maybe not.

Also with 2D arrays you can use the first dimension to represent a piece on the board, and the second dimension values to represent the piece type, coordinates, can it move(bools) and link it to its movement type. 

2 of those and you'd have one for yourself and one for your opponent. 

0

Share this post


Link to post
Share on other sites
9 hours ago, AlluMihu said:

is it a good idea to store hashes in a database as game states? ...  I find it easier using a database to store states. Can you tell me the advantages and the disadvantages? Thank you.

Apart from the mixed terminology already used, if you're looking to store values in a database, there are advantages and disadvantages (pros and cons) that all depend on what you are doing with the data.

If you're using a relational database, you'll want to have a format that allows you to follow your relationships and join whatever it is you need joining with.  If you are serializing data into fields that can be encoded in to records, then it may be a good fit.

But others may be a bad fit. If your serialization can't be used for relational purposes and you're trying to store them in a relational database's rows, then it may be a terrible fit.

You may be looking to build tables to solve the game, or to communicate with other players about the game, or to record checkpoints along the game.  You may be looking at ways to bill users every month for their play. You may be looking at something else entirely. Each goal may have different pros and cons for different storage systems.

 

7 hours ago, AlluMihu said:

Consider two players playing chess online...

For chess specifically there are two widely-used encodings.  One is called 0X88 that takes 128 bytes, the other is a bitboard that fits within 64 bits.  Both have their own pros and cons.

The 0X88 method is usually faster to manipulate on today's processors even though it is longer than a bitboard. The bitboard is great because of its small size.

For one useful example, if you're trying to communicate the state of the board a bitboard can use base64 encoding to encode it as an eleven character value. Base64 encoding uses plain text values, so someone could type in a board like "B4bmNvZGUgY" (made up example) and everyone in the world could use it to know the state of the board.

 

1

Share this post


Link to post
Share on other sites

There already exists a standard way to notate a whole chess board state: https://en.wikipedia.org/wiki/Forsyth–Edwards_Notation

Alternatively you can use a different notation to store the whole game including past moves: https://en.wikipedia.org/wiki/Portable_Game_Notation

Both are compact enough that you can store them in a single database column without problem.

2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now