• 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.

stitchs_login

Members
  • Content count

    142
  • Joined

  • Last visited

Community Reputation

1361 Excellent

About stitchs_login

  • Rank
    Crossbones+
  1. Great read! I've been having to do a lot of JUnit testing at my new job and this is completely fascinating/a way that I want to work in the future.
  2. I completely agree Nypyren. This is a self-imposed limitation that I am doing to test with that particular set of Unicode characters. I wanted to refine the method first, and then expand it to include a bigger character set.   Stitchs.
  3. Hi all,   I've been presented with a small challenge:   1) Make a function that counts the number of each individual character in a string. Report back to the user in the form <character, number of occurrences> the character that appears the most.   So the function would take a string input; i.e. "rabbit" and output the character that occurs the most in said string; i.e. <'b', 2>.   I have coded up a function (to my understanding of Big O notation is that it is Linear O(N)). public static string GetMostFrequentCharacter(string input) { string result = "The String is empty."; if (IsStringValid(input)) { int INDEX_CONVERTER = 32; int[] characterCounts = new int[127 - INDEX_CONVERTER]; char characterToConvert; // first loop counts the occurrence of each character in the string for (int i = 0; i < input.Length; i++) { characterToConvert = input[i]; characterCounts[(int)characterToConvert - INDEX_CONVERTER]++; } int highestCount = 0, arrayPosition = -1; // second loop finds which character appeared the most, only the last // highest count to appear in the list will count. for (int i = 0; i < characterCounts.Length; i++) { // check to see if the current index value is higher // than the previous higher count if (characterCounts[i] >= highestCount) { // get the value at the current index highestCount = characterCounts[i]; arrayPosition = i; } } if (arrayPosition < 0) { result = "There was an error in processing the string."; } else { // finally, convert the arrayPosition into a suitable char representation char characterToOutput = (char)(arrayPosition + INDEX_CONVERTER); // format the output string result = string.Format("<'{0}', {1}>", characterToOutput, highestCount); } } return result; } I'm happy with the way most of it works. My only problem is that, say I have 2 characters that appear an equal number of times. My current method only takes the last highest value, in order of UNICODE value. Say we have the string "foof". The output for said function would be <'o', 2>, it does not present the last letter to appear, only the last in order of UNICODE.   I don't want to create another storage for characters that appear equal number of times (I already have 2 arrays). I have looked on the internet, but the only responses I am finding is if someone knows the character they are looking for, before they use the function; they ask "How many times does 'a' appear?"   Any help or feedback would be greatly appreciated.   Stitchs.
  4. @ChaosEngine: I was going to implement it as a Generic Type, but I'm never going to use it for my projects and wanted something that I could get information from quickly, for testing, which is why I pre-made it using the String class.   @Pink Horror: I' guessing that if I wanted to look at/use every item I would (internal code): for(int i = 0; i < list.Length; i++) { DoSomething(currentNode); currentNode = currentNode.next; } User code: DoSomethingWithAllListItems(int pLength); This would be O(N) Linear as it will take an amount of time and resources proportional, to the size of the list (which if it gets very big, will cost a lot). If I want constant time, such as the change I have made to my AddNode() method, I would need to be able to access a node directly, knowing it's location beforehand.   I hope I have understood what you are trying to say, but what would be a constant alternative to looping the list. Would I have to order it first?   Stitchs.
  5. As an update: I went back to my AddNode method. If I use a reference (let's call it tail) which stores the final node in the list so that new nodes can be added without traversing the list. public void AddNode(string stringIn) { StringNode newNode = new StringNode(stringIn); if (IsEmpty()) { list = newNode; tail = list; } else { tail.next = newNode; tail = tail.next; } } What I'm struggling to understand is how my else statement works. It works, as in it adds nodes successfully. Can anyone clarify that my thought process as to what I'm doing is correct?   If the list is empty, I add the new node as the head and make the tail equal to the head (the head is both the first and last node).   If there is a node (say we are at the point that we haven't added anymore than one), then we make the tail.next (aka list.next) equal to our new node. Then we make tail equal this last node.   What I'm struggling to understand; once we exit the AddNode function, and the temp variable newNode is no longer in memory, what is preserving the references to these different nodes in memory? Only list and tail exist, I'm changing what tail points to every time I add a node to a non-empty list, how are any nodes in-between able to be referenced/not being flagged for garbage collection?   Please ask if you need anymore clarification.   Stitchs.
  6. Hi all,   Thanks for the feedback so far. I am implementing it to further my understanding of how they work. My intent would be to use the .NET implementation.   I did think as I was implementing the loops with indexes that what happens if the list gets too big? I know that each node is stored, non-sequentially, in memory which makes it longer to iterate over.   I have thought about adding a reference for the tail; making it the result of AddNode().   What I'm stuck on is the idea of holding a place in the list. Isn't this just as slow as starting from the beginning? If you start at the beginning then you don't have to worry about going backwards. Otherwise I need to create a doubly Linked List to be able to traverse back and forth.   I have some great feedback to work on from this.   Thanks,   Stitchs.
  7. Hi all,   I am part way through implementing my own Linked List class (only stores Strings for now) to better understand how they work. I have completed the major portions of it; Add, Delete, Insert etc. and was just wondering if I could get some feedback on the code thus far. private StringNode list; public MyStringList() { list = null; // empty by default; } public void InsertNode(string stringIn, uint index) { // Check that user is not trying to insert outside the valid // range of nodes. if (IndexOutOfUpperBounds(index)) { return; } // create a string node to insert into the list StringNode newNode = new StringNode(stringIn); StringNode current; StringNode temp; if (index == 0) { // store the list head. temp = list; // set the new node as the new list head list = newNode; // reconnect the old list head to the new list head. list.next = temp; return; } // temp node that is a reference to the beginning node current = list; // loop to the position of the node at index // because of the way that current is initialized, we can // skip index zero. for (int i = 1; i < index; i++) { // check that there is another node to process. if (current.next != null) { current = current.next; } } // store a reference to the next node (the one at the index we desire) so as to preserve it temp = current.next; // set the current.next to point to the location of the new node // and set the new nodes next to point to that of the old current.next = newNode; newNode.next = temp; } public bool DeleteNode(uint index) { if (IndexOutOfUpperBounds(index)) { return false; } // temp node representing the current node in the list. StringNode current = list; // temp node representing the previous node in the list. StringNode previous = null; // if the user has searched for a node that is not the first in the list if (index > 0) { // loop from 0 to the index position. for (int i = 0; i < index; i++) { if (current != null) { previous = current; current = current.next; } } } // need conditions to assure that the predecessor of a node, // removed from the end will point to null // a check to see if we are at the end of the list. if ((current.next == null) && (current != list)) { // make the very last node null, so it will be removed by // garbage collection previous.next = null; current = null; } // condition that a node removed from the middle will link the two // nodes that surround it, properly else if ((current.next != null) && (current != list)) { // change the previous node to link to the node up ahead. previous.next = current.next; current = null; } // condition that the successor of a node removed from the front // will properly set the new list head. else { // check that the list head is not the only node if (current.next != null) { list = current.next; } else { list = null; } } // reduce number of nodes by 1, if we have got to this point, // there is no need to check if we are allowed to decrement. this.Count--; return true; } I have not included the entire implementation, for simplicity's sake. I would like to draw your attention to the Insert and Delete methods. They work in all the tests I have performed. I feel like they could be streamlined more. If you need anymore information, feel free to ask and I shall do my best to explain.   Many thanks,   Stitchs.
  8. Wow. Thanks for all the response guys. You've given me a lot to think about.   I'm actually eager to finish this chapters exercises just so I can go back to the Deck example and implement these new ideas.   When I first saw the problem, one method I kept coming up with was swapping cards, but ignoring ALL cards previously swapped. Not just the card put into the visited portion. What is the 'bias' being quoted? Is this more to do with the computation of the randomness, or the same as the randomness created during a 'human' shuffle?   My thanks,   Stitchs.
  9. It was, initially, but as I researched shuffle methods I wanted to push myself and design an algorithm to represent one.   Your way is simpler, and that helps me appreciate that I might have over-complicated it, to which I thank you.   @Nypyren: I have read into the Fisher-Yates and I was planning on implementing this next, to compare.   Many thanks,   Stitchs.
  10. Hi,   My apologies. That is the implementation for the DrawCard(). It gets the card at the top of the List, removes that card from the list, and then returns the Card for use by other functions.   I did think about reserving memory for the initial list. Should I just reserve 52 elements worth of space for all 3?   Regarding the Overhand technique, I attempted doing one cut, but all that achieved was slightly adjusting the positions of the cards, keeping them in the same order. The way I saw its execution, before performing 2 cuts, was that it took a random amount of cards from the top, appended them to the back of the list, and repeated. This didn't achieve anything.   How else would I go about the Overhand shuffle that it avoids this problem?   Many thanks,   Stitchs.
  11. Hi community,   Working my way through a book, I've come to that classic "Create a deck of cards and Shuffle method" question.   I research shuffling techniques online as I wanted to implement this on my own. I decided to use the 'Overhand Shuffle' technique (details found: http://en.wikipedia.org/wiki/Shuffling#Overhand_shuffle). The basic premise is that you cut the deck and at 2 points and move this middle section to the top, or bottom, of said deck, repeating until sufficiently shuffled.   I have created a method that implements the same behavior: public void ShuffleDeck(Random pRng) { int deckCutPoint = 0; List<Card> firstCutDeck = new List<Card>(); List<Card> secondCutDeck = new List<Card>(); for (int i = 0; i < MAX_SHUFFLE; i++) { // RNG a point at which to cut the deck. deckCutPoint = pRng.Next(DECK_LIMIT); for (int j = 0; j <= deckCutPoint; j++) { firstCutDeck.Add(DrawCard()); } // RNG a point at which to cut the deck, based on the new deck count. deckCutPoint = pRng.Next(lDeck.Count); for (int k = 0; k < deckCutPoint; k++) { secondCutDeck.Add(DrawCard()); } lDeck = lDeck.Concat(secondCutDeck).Concat(firstCutDeck).ToList(); // Clear the cut decks so that they can be reloaded on the next shuffle. firstCutDeck.Clear(); secondCutDeck.Clear(); } } I have a list of Cards in my DeckOfCards class. This is the main deck. I create 2 more decks in my method, that I use to draw cards out of the deck, adding each card to the back of the list. I randomly cut into my deck the first time by using its size to generate the index position. I do the same for the second cut, using the updated size.   To achieve the actual shuffle, I Concat the secondCut to the original deck, and then Concat the first cut to the back of the now modified main Deck.   My question/desire for feedback is how efficient is this? I understand that each time I draw my original list is getting smaller, and new memory has to be allocated for the new temporary lists. FYI; MAX_SHUFFLE is set to 25, meaning it repeats this process 25 times.   My thanks in advance,   Stitchs.
  12. Hello,   I am working on an exercise for C# that involves reading from a Text file, extracting any Integer values (+ or -) and displaying them in the console window, in a tabular format.   On a 'one value per line' basis, I have managed to accomplish this. My code runs through the text file, ignores any decimals or non-numeric characters (NNC), and outputs Integers into a table.   I want to make this a bit more robust, the exercise never specifies how text in the file should be laid out, so I want to assume that having multiple Integers, Decimals/NNC on the same line can be accounted for. These would be separated by Whitespace.   My pseudo-code would be as follows:   while Not at the end of the Stream create a StringBuilder while StreamReader.Peek is not a whitespace or null (should break on detecting whitespace) append the value at StreamReader.Read() to the string builder Try to parse this new string to an integer data type for output later. Repeat My issue stems from points 3 and 4, the inner loop. Peek doesn't seem to recognise a whitespace value and the loop won't break.   while (!String.IsNullOrWhiteSpace(sr.Peek().ToString())) {        sb.Append((char)sr.Read()); } sr is the StreamReader object. Is there something I'm missing here, or am I making it too hard on myself?   Please ask if you need any more information.   Many thanks,   Stitchs.   Update: I have stepped through the StringBuilder every time it is appended too, and have also found out that Read is also taking the \n and \r escape sequences into account. How would I account for these?
  13. Thanks, I really like the way you've broken it down.   I don't think the book expects it to be to this level of detail, but I will try to incorporate it in redoing this solution.
  14. Hello,   I am working through a programming books exercises. I am on a chapter dealing with loops, and an exercise that makes use of inner loops. The aim of the exercise is to print a limited number of rows, each one printing a certain amount of spaces and stars:   -----* ----*** ---***** --******* -********* -********* --******* ---***** ----*** -----*   I have come up with a solution, but it seems a bit messy to me and I cannot figure out how to clean it up. int MAX_ROWS = 10; for (int row = 1; row <= MAX_ROWS / 2; row++) { for (int space = row; space <= MAX_ROWS / 2; space++) { Console.Write("-"); } for (int star = 1; star <= row * 2 - 1; star++) { Console.Write("*"); } Console.WriteLine(); } // Variable to subtract the number of stars to be printed on every run // of the second loop. This is decremented on each full run of the outer // loop. int starReducer = 5; for (int row = 6; row <= MAX_ROWS; row++) { for (int space = 1; space <= row - 5; space++) { Console.Write("-"); } for (int star = MAX_ROWS - 1; star >= row - starReducer; star--) { Console.Write("*"); } starReducer--; Console.WriteLine(); } (The dashes are meant to be spaces, but are used to show if the loop prints the correct number of characters).   My issue comes from the two nested loops dealing with drawing the stars. On the first 5 rows, I want the star count to be ascending, adding two more stars to each row, at a time. I currently do this by setting star count to one, and it loops until star count becomes <= (the current row * 2) - 1. This prints the required; * *** ***** etc. for each row.   The second sets star count to 9, and does a reverse loop that stops when star count >= the current row (starting with 6) - (a new variable to reduce the amount that the loop counts down each time) starReducer, which is decremented on every completion of said loop.   Is there a better, cleaner solution to this? It works but it bugs me that if I were to come back to this in a few days, it might not be as clear to me as it is now.   I appreciate anyone who takes the time to have a look.   Many thanks,   Stitchs.
  15. Hi, thanks for the responses.   I see what you are saying, maybe I'm a bit out of my league on understanding the ins-and-outs of it.   I looked into the suggestion of rounding the approximation, to that of one decimal place. It seems to have worked. I wrapped my previously explained method in a Math.Round() function.   I have started reading the suggested article, hopefully this will open my mind a bit!   Thanks again,   Stitchs.