Tuesday, November 19, 2013

Too many things happened in my life during that time but it's not topic for this blog, then, what about code this time?

Simple put, I needed shuffle a simple List in C# and I was not able to find some easy way over the internet, so I spent some minutes to create my own way, a small handly function to shuffle IList, use it, enjoy it and improve it (in this case, just let me know how to do it better).

Tuesday, November 10, 2009

Question? is that possible to create an architecture, interface based, which allows you programming a game flow independent of his content?

answer: yes!

Note that Minigame_Pinball and Minigame_Pinball_Score are just interface implementations that don't know nothing about the game flow, they are using IGameObj to connect to the flow and returning a condition from FLOW_CONDITIONS, they register themselves and they are allocated only when I need them :) (it's easy to pre-allocate if you want to)

Now, you can copy the code, create your own game class, derive that from IGameCreateObj and implementing your own IGameObj and have fun!!!!

Monday, September 24, 2007

Sometimes you get all information you need in one book only, but sometimes, even including all information directly from core, it's possible that book has not been written best way it could do, I'm mean format.if you ask me a good book about Design Patterns I would like to suggest two, first one it's the bible:

I'm used to say if you want to learn about C start reading “The C programming language” from Kernighan and Ritchie or if you want to learn about C++ start reading “The C++ programming language” from Stroustrup because those books are bibles written by creators of those languages; to learn with creators really works for me, the same can be said about Design Patterns, you can start reading the book above, after a first contact with idea, in order to get some fluency, you will need practice, more research and more samples, internet is full of them, but you know internet is a free land, so take care with pseudo gurus; in order to help you, I would like to suggest a second book about patterns that worked for me, this second book has a practical approach, I love practical things, less academic, the only bad point about this book is about language, they have been using Java, I’m not a Java programmer but if you know C++ or even C+# and OO you can read without any reserve.

I've friends that confessed me they ignored this book because the cover, don’t do that, it’s a nice book!Keep studying and keep creative.

Another very very nice work, this time, they've provided codes in other languages and all kind of examples; really excellent job.

I’ve decided to invest 15 minutes from my spare time, so after 5 minutes trying the conventional approach I just decided change strategy in order to make that function work in the last 10 minutes; Pressing creative button all became clear: we need to return a number that needs match AB range, the difference between A and B can be considered a distance as well, a percent, that was my approach:

Saturday, August 25, 2007

Recently I was interviewed for a big company, (no names here); it was an exciting and interesting interview by phone; the recruiter started asking me about linked lists, data structures, collisions trees, path finding, etc… It was strange talking about code by phone, I had never been interviewed that way before, not by phone; worst than that I was under strong medicines, I had caught a cold one night before, summarizing, that was not my day, during interview one of the questions allowed me show to recruiter exactly how I’m used to think, He asked me:

"How would you implement the rules of a Tic Tac Toe game?"

He asked me to think while telling him what I was thinking. I was under pressure and doesn’t matter how much recruiter tried to calm down it was still an interview for a big company, describing code techniques by phone, so I started answering conventional way, I meaning not the way I'm used to do, (creative way), I started creating a 3x3 matrices considering game positions, etc… suddenly some voice inside of me started screaming: “Wake up Flavio! What you are doing! that’s your opportunity to show how you think, don’t fear, don’t be conventional!” Instantly I started thinking the way as I’m used to do, I'm used to think visually first, metaphorical way second, design third and coding at last so I said to recruiter: “Forget everything you heard I would like to start again, Tic Tac Toe is a game which the rules are fixed, it never changes, you can visualize board so that, you can see results visually and map them all in any place, its about 8 possibilities of victory starting count after three choices, a bit field should work fine for that" so I suggested a bit field which would avoid matrices manipulation overhead. I felt some “what? show me the money” feeling coming from other phone line, and He asked me to tell him the code for this, by phone, He asked me to write the code in a piece of paper, or compiler, or any text editor and keep telling him what I was writing and thinking, well, I was not comfortable, I was sick and under pressure and I was not able to do the code that time, after sleep a little and wake up better here is the code.

// tictactoe.cpp : This code is only for illustrate an idea.// 08/26/2007 by flavio.rodriguez@gmail.com

/* * Although this code works it was made as pseudo, I mean no structure or functions, * the objective here is just check victory * then imagine a player called A */ unsigned long playerA = 0;

/* each quad represents a position in game

| | | | |--|--|--| | | | | |--|--|--| | | | |

and here is their relative values

|1 | 2| 4| |--|---|---| |8 | 16| 32| |--|---|---| |64|128|256| */

/* * Now you can simulate any player move; * in case of two players, we should just to create a player called B * each time player click a quad, a bit is incremented * and that would begin to be tested after the third move, once * before that time we don't know winner */