CS Course Day 66
6.00.1x Problem Set 2:
6.00.1x Problem Set 3:
CS106A PSet 6:
CS106A Asn 5: Yahtzee.java:
03-Feb-2016 11:29
Working on CS106A Assignment 5: Yahtzee
Assignment page can be found here:
A very helpful video tutorial if you find yourself stuck:
I got the first part of the program working. I used a tutorial video (Hack Your Knowledge) after brainstorming for a couple hours on part 1 to help speed myself along. You can call it "trying to optimize the learning process" or just being lazy, anyway I'm on the clock. But it's pointless if I'm not learning; so after paying attention on the logic of what was being said, I went back and erased methods to see if I could create them on my own. It worked.
I'm at the stage of a Yahtzee game where a player selects a scoring category - this is after every turn which is 3 rolls of the dice. After category selection, the computer checks if the category is valid. If so, the score is added to the scoresheet, which is a 2-Dimensional Array (so you're specifying the right 'box' to assign the score to). A couple questions I have here are: if the player selects an invalid category what happens? Does the game give them no points and continue on (wasting a turn for the player)? or does it prompt and let them pick again? The 2nd sounds more logical.
I don't know the game of Yahtzee well either: can a player replace an old score of a certain category with a better one? But there're 13 rounds so each round has to fill something.. that would imply No. And if they rolled something that only fit the "Chance" (any combo) category multiple times? Well then it seems logical that you wouldn't get a Full House or a Large Straight every single game.. so yeah you're going to have empty scores.. which, if you're adding them up at the end: either skip a score if it's empty ( scoreSheet[x][y] == null ) or assign zero to all.
03-Feb-2016 11:40
Ah okay, the player must select a score category, and if it's not valid, they just score 0 in that category. That makes totaling scores simpler. So selection is matter of using the appropriate call to the YahtzeeDisplay class that's provided.
03-Feb-2016 12:00
It looks like I'll have to create a switch to retrieve scores based on category number.
03-Feb-2016 12:58
Here's a note of interest: leave complexity where it needs to be. I'm trying to write conditions for the different scoring categories. This is easy for the 'Upper' scores: just add the dice of a specific number. It's complicated for the 'Lower' scores: Three & Four of a Kind, Full House, etc. So what to do? Well the method I'm writing to calculate category score is concerned with exactly that. Figuring out the implementation of special cases (how to check for three of a kind for example) is beyond it's theoretical purview, if I may. That is another level deeper into the program. This reminds me of an SICP lecture by Gerald Sussman (.. or was it Abelson?) where he talked about treating a program's structure as successive layers of language that describe things in a certain level of detail appropriate to the general goal of that level. Maybe I'm wrong but I think I'm seeing that here.
Importance: I could very well just figure out some way to force through the algorithm and make it all fit inside the calcCatScore() method, but I'd be doing what those MIT professors warned of: building a machine of intricate parts that each accomplish a discrete task, break any and everything built on it crashes. Doesn't matter much now, and the computer may not care, but in the future I and my future employees will be glad to have a common line of sense running through any set of code. I guess that's the Computer Science side of things.
All good engineering is built on wishful thinking - G. Sussman.
04-Feb-2016 12:57
Finished debugging Yahtzee. Took a few rounds of testing. There were two issues: First the score returned to the display was off by 1. The index used for the dice is the same as the int value for the variable constants of their faces, but they're zero-indexed. For the proper score you need to add 1 to it. Secondly there was a logic error: when checking the arraylist of dice faces, if you check only for equality you will disregard cases where more dice than necessary fulfill a given criteria. So if you need say, 1-2-3-4 in order, but you have more than one of any, your score will be zero, which is wrong. So you check that the index of the arraylist of dice is greater or equal to one. That's it.
A very professional and media savvy photo of the final product below:

No comments:
Post a Comment