Placeholder Image

字幕表 動画を再生する

  • All right.

  • Hello, world.

  • This is CS 50 on Twitch.

  • My name is Colton Ogden.

  • Apologies for the microphone being muted.

  • I turn it up briefly and forgot to turn it back on.

  • Um, this is part two of our stream on Solitaire, also known as Kalon Dyke.

  • And it's a popular card game, or at least was popular in Canada and the United States.

  • Last week, I'm gonna transition in my laptop.

  • We ended things with things with a board sort of like this with a little bit of grid grid layout in the background, some cards.

  • And this was just kind of a test to make sure that we had our our deck actually working with random car draws indigent to the ability to click and drag a card around there.

  • Just a sprite backing rather.

  • But you know, things are sort of moving in the right direction.

  • But we do have a long ways to go.

  • For example, today some of the things that I'd like to bite off our one actually laying out the board in a way that makes sense normally in solitaire, things air laid out such that and we'll look at Google images in a second.

  • But cards are laid out here in a sequence at the bottom, this bottom row saying with one card than two cars than three cards and four cards, et cetera.

  • With only the top card being visible, you get a deck up here in the top right, which is important.

  • That's where you draw cards from to put them into more piles on and then at the top, which you can't actually see.

  • Because the current algorithm is laying the cards out a TTE, the very top left.

  • You're actually stacking all the cards of each suit from the bottom to the top from Ace to the King.

  • So to answer our meats question, the topic of discussion is solitaire.

  • So we're using love to D today on the framework.

  • Love to D is a really nice framework for Tootie game development.

  • You gotta love to d dot org's.

  • We talked about this in the last Dream episode.

  • Definitely check that out if you haven't already seen it, where we implement everything from scratch, including parsing a spreadsheet of all our cards, laying out the grid, creating a deck class and a card class which we can then shuffle the deck and draw cards from which is very important because this is sort of the backbone of our whole game.

  • But more on that in part, one part to today is gonna be much more about the actual algorithms of laying out the board, getting to click and drag run piles of cards, and we'll see just how much we can implement before we get to potentially apart.

  • Three.

  • If we're very lucky, we'll finish apart, too, But I don't think so.

  • It's a rather media game, so thanks everyone for tuning in.

  • I got as Lee in the chat Male cat, uh, meet Microsoft India.

  • Pekka Mika to that chat cat Male can asked.

  • Well, I talk about machine learning.

  • Probably not machine learning today.

  • I'm not a machine learning expert, but, uh, would be nice to get somebody in the future who is more well versed in machine learning, such as?

  • Maybe Nick Wang, who did a prior stream.

  • If you haven't really watched the stream on binary classification with Nick Wong, definitely check it out.

  • It's on YouTube, probably not on twitch anymore.

  • It was one of our earlier twitches, and there was only saved for 30 days.

  • But yes, we are indeed continuing to make solitary meet Microsoft.

  • India says please share the link.

  • Yes, absolutely.

  • So I'll share two links in the chat.

  • Here.

  • Let me just pull up the repo name.

  • So I remember 100% what it was.

  • I have the code from last week on Get hub.

  • So if your are tuning in and you want to clone the code if you end up cloning the code Now, if you're watching this on YouTube, chances are the code's not gonna be the same as this, right at this exact moment in time.

  • Luckily, you can download arbitrary commit if you want to.

  • Unfortunately, for some reason, get up is taking Ah, long time toe load.

  • I'm not entirely sure why, but looks like it's working.

  • I saved it as solitaire stream, So I'm gonna take this into the chat here.

  • Hopefully, this doesn't cause any issues.

  • I just eliminated the Mac Rose on this machine so that I could actually type stuff this week.

  • Um, get up dot com slash colton Oscar P slash solitaire stream.

  • Take that and that should allow you to download the repo.

  • Uh, if you don't know what love to D is and what's.

  • I just ended up switching my view to the wrong one again.

  • If you don't know what Love to D is, you follow that link.

  • Downloaded.

  • It's a cross platform framework for making Tootie Games Institute.

  • Ian left to be done or unfortunately, doesn't let you make three D games.

  • I'm waiting for the day.

  • Love three D comes out.

  • I think that would be amazing development, but, alas, it is not a real thing yet.

  • So solitaire for those unfamiliar, let me just pull up an image of the solid terror starting layout so we can continue and sort of have a visual goal of where we're going next.

  • This is where we're going next.

  • It's not going quite like this.

  • This is a little bit fancier texture work done on it, but you can see that the grid is actually very similar to what we laid out last week.

  • You have seven rose, seven columns.

  • Sorry.

  • In the bottom row here, these are your stacks tableaus goes of different terminology that I'm not 100% clear on.

  • And you can notice that the cards start off on the left, with one card being drawn and that one's face up.

  • The second column has two cards, the top of which is face up the bottom would, which is face down the 3rd 1 The top card is still face up, but every card is face down and you can see the pattern continues on until the seventh column.

  • So you get all of these sort of areas to start laying out cards from left to right, and they increase in going toe in that direction, going towards the right one at a time at the very top left.

  • This is where the actual game is won, and we haven't covered this in too much detail yet.

  • But by stacking every card of each suits, remember, therefore suits ace diamonds, spades, clubs.

  • So by stacking every card, every a soccer star, every diamond card, every heart's card, every club's card, every spades card from a stick king.

  • That's how you actually win the game.

  • And so what you're looking for when you first start is, of course, an ace, because if I if I find an ace while I can stack in a CE here or an ace here an ace here, depending on which suit it is right.

  • And that gives you the ability to then lay a two on top of that and then a three on top of that.

  • And by the time you finally make your way up to King, you've won the game.

  • If you get all four of them out and to get new cards, which you can lay out either here on any of these piles or on these four winning piles, you have the deck here that you can draw cards from.

  • It's also called the Stock.

  • And so if I draw, for example, in a CE right here, I could put that in one of the piles.

  • Or if I draw a, for example, a um and it goes, um, lower value down.

  • If I were to draw a three a black three, I could put it on top of this red four, right, because the cars that you lay out all of these, this is an important rule of solitaire.

  • When you're laying cards out on your seven piles, they need to alternate in color, and they need to go from top to bottom.

  • They need to go from King down to down to ace.

  • So this four, for example, I could put a black three either a club or a spade three on this four.

  • I could put in a CE on this, too, but I'd probably want to put the ace on one of these piles here so I could start building up my, um my winning piles, right.

  • Wanna put the ace first?

  • That's the card you're looking for.

  • I could put a black eight right here.

  • I could put a red Queen here.

  • I could put a red six here, a red seven year red to here.

  • And this is how you build up your piles that you can move around eventually.

  • If you build all your piles in descending sort of order amongst your seven tableaus, you could very easily take cards from any of these piles and then put them in your winning piles.

  • And so this is a refresher on how the mechanics of solitaire work and so that we have a clear picture of where we're going as we implement our game.

  • An important thing that I think we should first think about implementing is populating these seven columns down here in this bottom row also probably want to get rid of this drawing these five random cards on.

  • Then maybe also just rendering a card backing here.

  • And that will be representative of our deck tux.

  • Man, thank you very much for tuning into the stream.

  • And thank you very much, too.

  • Kay's Oxy and South Africa for the follows right before the stream started, uh, again, any questions on the rules or what we've done so far?

  • Definitely the minute chat.

  • I'll be watching that as we go along twitch TV slash CS 50 TV as well.

  • All right, so let's take a look here.

  • So what we did last time was we implemented the game board, and what this was was just are basically just drawing the screen green.

  • And then those rectangles, though the grid layout for where we want to place our cards.

  • And that's essentially the backbone of where we're going to end up placing stuff.

  • And we're probably gonna want some notion of a card pile later on, which has a bunch of cards in it.

  • And those cards are gonna have to enforce their order and their colorization.

  • So we're gonna need to worry about that in a little bit.

  • What I want to do is I want to get rid of the sort of arbitrary rendering that we already have.

  • So what I think I did was in the deck class.

  • I made a render function here that just drew the 1st 5 cards in the deck.

  • And I don't really want that.

  • I don't want to draw those five cards anymore, so I'm actually just going to pass on that and re render it and notice that now we're no longer drawing those five cards.

  • And we indeed have our grid layout, as we saw previously, right?

  • I also probably don't need this random card that I can click around.

  • I could get rid of that pretty safely we're implementing we implemented is such that I can click to start the drag, and then it'll just follow my mouse and then click again to a new drag.

  • Our undrafted, the card and smart 13 18.

  • Thank you very much.

  • Oh, thank you for cool hairstyle.

  • Thank you very much for the car.

  • For the confident.

  • I appreciate that.

  • Um, so I think in card, actually, we may have been doing that in here?

  • Let's see.

  • It might have been in Maine, actually.

  • Let's make sure.

  • Yeah, I think Yeah, we we were rendering a queen of Hearts.

  • We we chose to render a queen of hearts just as a test to make sure card class was working.

  • You can see here in my directory, and this needs to be shrunk down a little bit.

  • I can get rid of some of these, but notice that I have a in my source directory in the repo.

  • And if you've cloned the Rebo, then you'll see this.

  • I have a card class, which is just representative of what a card is, which stores a suit and its stores of face value, which are two important things that we need to take into consideration for algorithm will need to check to see one.

  • When we place a winning card down in one of our top tables up here, we want to enforce that.

  • Each of these piles is just one of the same suit, right hearts, diamonds, clubs and spades.

  • When we want to actually stack them, we need to worry about the face value.

  • Whether it's a 34 Queen King, we'll do that, not only here in the winning piles section of our code.

  • We're also taking into consideration the suit, but we're also going to need to take into consideration.

  • Um, well, actually, we need to take into consideration the suit and the face value when we lay it down on the tableaus, too.

  • Because remember, we need to enforce a red black sort of progression of cards down the line.

  • Now it doesn't need to necessarily be one suit or the other a specific one.

  • I just need to be one of two if it's a red card, if it's a heart or a diamond, it card needs to be clubs or spades in order for us to lay it down and vice versa.

  • So that's just one thing that we need to take into consideration.

  • So that's why we have a card class.

  • The card class maintains a reference to its face, its suit, whether it's hidden, whether it's picked up and it's X and Y value so that we can render it to a given place on the screen.

  • There's also a deck class, which just maintains a list of cards that are all shuffled.

  • We wrote a shuffle algorithm.

  • Last time the, um, somebody refresh my memory on what the shuffle of, uh, it was Yates Shuffle.

  • What was it, Barry?

  • It's truffle, uh, and also known as the New Shuffle.

  • I think that was what Fisher Yates shuffle.

  • That's what it is, essentially just taking a bunch of random, basically indexing into our deck at random, putting it into another temporary deck and then eliminating that from the prior deck, which saved us a little bit of Spar City.

  • We don't need toe keep rule.

  • Re rolling are random ization if we end up messing up sort of how we take cards out of the deck and also shout it to David for tuning into the stream.

  • Um, in a tux.

  • My looks like Tech Man's about to say something for the card placement within the rose as well, so that was what we did with the deck class.

  • Very important, we'll be using that to draw individual cards for our stock later on in the game we needed to dependencies module so that we could actually not only specify where are textures are laid out, but also to slice them apart and store reference to the quads that we used in the last the last video, which were just rectangles that represent a chunk of our texture because we don't want to draw our entire spreadsheet recall, and we'll pull this up here.

  • The actual Sprite sheet for our game is this large chunk of graphic, right?

  • It's all of our cards put together into one image, and we don't obviously want to draw that anywhere in our game.

  • You want to drive just a piece of it.

  • So we define what's called a quad or rectangle.

  • I'm sure for quadrilateral Justin X y in the width and height, and by passing that into a function in love to D.

  • It'll just draw that piece of the texture won't draw the entire thing.

  • And that was a part of the last dream.

  • Turn into a last dream for how we actually implemented that we were a couple of functions.

  • We had to end up actually fixing orographic a little bit because for some reason, some things were out of order.

  • Um, and even after we did that, cards were still in the wrong order.

  • Queens were coming before kings and Ace was coming before 10.

  • It was kind of a mess, but we fixed it in code, which is an important lesson.

  • I think even dealing with graphics on this has come up in some comments as well, when dealing with graphics that you don't have any control over their layout.

  • Sometimes you do have to in code, fix things yourself.

  • So it's an important at least lesson to be aware of.

  • Ideally, though, work with an artist specify for them.

  • I need graphics laid out in this way.

  • I need everything laid out ideally in a systematic way so that you can algorithmic Lee sort of spice things in a clean way.

  • But, you know, you always have that luxury.

  • Always work with an artist, and you might not always be talented like myself.

  • I'm sorry you, like myself will not be talented unnecessarily to fix the artwork that you were given.

  • So sometimes you have to use code instead of, you know, digging into it with photoshopped or gimp or a sprite or et cetera.

  • Um, will this solitary game tell us when we have no moves left and we have effectively lost?

  • Uh, we can implement an algorithm for that short all we have to easily D'oh!

  • Um, well, isn't gonna be easy to do necessarily.

  • I think so.

  • Because you off.

  • You just have to reiterate through all the card piles.

  • Check to see if they have an available move.

  • And if they don't have an available move and you can't move your car to the winning piles, then you've effectively lost, including your stock.

  • So, yes, it is definitely possible in my blackjack game.

  • I just picked a random position from an order deck.

  • Yeah, uh, it's referring to the shuffle.

  • Yeah, that's effectively what Fisher Yates is, but just a little bit.

  • We add a little bit of a refinement on Fisher Gates and harder problems.

  • Thank you very much for the kind comment.

  • Um, as the saying, you're very talented.

  • Remember the awesome flag pixel art?

  • I appreciate it, but I don't know if I would go so far as to say that, but I very much appreciate it.

  • I wanted to ask for the placement.

  • A black card, for example.

  • Would it be simpler to use heart or diamond or at an additional value to the card as red?

  • Um, I'm inclined to say that since red is a derived value of properties that we already have in the card.

  • We probably wanted just keep the heart or diamond and just using.

  • Or in that case, rather than create new value, that weaken derive from the existing value on.

  • And there's an argument to be made for against this.

  • But I think the only time that what you want to consider this is when it's very computational e expensive.

  • Um, so I'm I am more inclined to say, well, using or in that case and not at at new data that we can easily just drive with a simple condition.

  • Cool.

  • So we have the board all laid out.

  • We were just looking at the different modules.

  • Dependencies were restored in parcel of texture data.

  • The game board was where we actually drew the background Weaken, jar, deck.

  • We're gonna end up drawing all of our card piles, which are gonna be very important because we're gonna have different stacks of card piles.

  • Um and then we also had a util function and the u.

  • R i u till module rather a file that you told a little file which had a few functions in it for parsing are our texture for quad, so splitting it up in the quads and also fixing the fact that they were a kn ordered when we parse them.

  • And we also used the beautiful tool called Stack overflow to find a function called Dump, which just recursive lee prints a table because I didn't feel like writing it from scratch ourselves.

  • But all it does is just writes out a table, depending on if it's a table or not up with the value, it nicely puts brackets, curly braces.

  • Thio at least tell you that you're working with a table and will Riker silly call itself and then to string edge each non table value so that you can eventually see your entire layout of data.

  • And then we had a re sort function that ended up sort of putting our cards in the right places.

  • So that is a rough breakdown of what we did last week.

  • Now the first thing that I want to do so that were, at least visually seeing where we're going and sort of sanity checking the flow of our game, feeling more accomplished than we might actually be, is laying everything out um, on the bottom row.

  • So let me go ahead and go back to deck so that it renders what well we saw in the graphic recall was that the piles from left to right start with one cards, then two cards than three cards, four cards, five cards, six cards and then finally, seven cards.

  • The top card is always face up the bottom cards air face down and you reveal cards as by taking cards off of them.

  • So, for example, in this second pile and I'll go to the image here in Google.

  • If I take this to off of this car down here, I can flip that card over, and we'll implement this with right click.

  • Probably I can flip that card over, and it becomes a card that I can now move wherever I want to move it.

  • If it's a swell, I just revealed an ace.

  • I could put it in one of my winning piles.

  • If it's for example of black three.

  • Well, I can put a black three here and then maybe move this king over here because you have thio end up.

  • You know, I believe it's a rule where you can on Lee.

  • Put a king on to an empty slot in your tableau.

  • I'm not 100% sure about that.

  • Actually.

  • Solitaire Move card to empty tableau.

  • Um, yes.

  • If any of the tableau piles are empty, you could move a king there.

  • Right?

  • Okay, so that's good.

  • I'm I am saying you it has to be a king.

  • So if there's an empty slot, let's say I move this too right here.

  • Let's say I move that onto an ace pile up here.

  • Let's say I got an ace.

  • Put it up there.

  • I was an ace of spades.

  • Put it to up there on top of the ace of spades.

  • I'm building that that spades pile up.

  • Now I have this blank card here.

  • Let's say let's say that's a black three.

  • I moved the black three onto this four.

  • Now I have an empty tableau.

  • I can put this king over onto this empty tableau, and now I've sort of opened up a new pile that I can start digging through, and this is sort of the the fundamental way of playing the game.

  • The loop of the game is just kind of revealing cards moving cards around until everything sort of falls into place.

  • But yes, that is thief Flow of the game regarding the schedule Is South Africa off by a day?

  • Because it's Monday here, Um, the schedule should be up to date.

  • It might just need to be shifted one day over one card, two cards.

  • I'm getting a Mario dot C vibe here.

  • Oh, yes.

  • On Lee on an empty spot.

  • Um, one card, two cards.

  • Uh, I'm not entirely sure what you're referring.

  • Thio, if you can clarify that for me 100% short.

  • Um Okay, so let's go ahead and think about what we're going to need to do in order to.

  • Well, first of all, we're gonna need to move cards around.

  • And not only are we gonna need to move cards around, but we can actually move piles of cards around from our tableaus, so we will need some notion of a card pile.

  • Right?

  • And at least this is how I want to frame the game.

  • You could frame this in a multitude of ways.

  • You don't necessarily need to abstracted in this specific way, but I'm inclined to say that I'm probably gonna want a card pile class.

  • And, um, this is all from scratching off the cuff.

  • But this is just how I go about approaching problems like this by thinking about the objects in my space the sort of interactions they're gonna have and sort of building up the building blocks that I'm gonna end up actually composing to create my game in this object oriented way.

  • So this is gonna be a card pile.

  • Class A card pile.

  • Class is kind of like a deck, but it's not gonna have a shuffle method.

  • It's going to have Theobald ity to, I think, move around necessarily.

  • Probably we could also implement this in another way we could do is we could have each individual card, parents, other cards.

  • We could have it such that this nine, for example, is a parent of the eight below it.

  • And that eight is a parent of the seven below it.

  • So there's always this direct chain of parenting, right where you have a card that's apparent of a car that's a parent of a cart, kind of like a list, almost almost like a link list.

  • And what we could therefore do is by moving a parent.

  • You move the child when by moving the child you moved its child because we could just have each card reference.

  • It's parents position.

  • And by doing that by just, you know, calling update and moving something and checking to see whether it's parent is in a different position.

  • Um, we Therefore, it can move multiple things at the same time.

  • So this is probably the route that were in going to end up taking, Um, nested four.

  • Looks like Mario see from this.

  • Oh, I see.

  • Um oh, right, Yeah, it is kind of like a memorial pyramid.

  • Now that you mention it, it's kind of like a Mario pyramid that's been rotated 90 degrees to the left.

  • I agree.

  • Yeah, it's kind of it's very similar to that.

  • Um, this one's a little more complicated just because we have to enforce that the bottom most card, rather the top most card, is always face up.

  • So we will be We will be doing that.

  • Um, so now I'm actually wondering whether it's even necessary for us to press to implement a card pile class because we could just enforce this parenting in this piling behavior almost emergent Lee using just basic parenting.

  • So that might be that might be a place to start.

  • Why don't we start there?

  • So rather than we won't worry about card piled out, Lou it too much just yet.

  • But we will do is we will go in a card and we'll say that every card should have a parent, right?

  • Or at least it should have a parent field that we will eventually care about likely.

  • And I don't necessarily think that it should have a child, or we should necessarily need to worry about whether it has a child.

  • We can probably just assume parent, and that will be fine.

  • We will actually care about whether so I think we will need card piles for the winning piles.

  • We will need you and those are actually gonna be rendered differently because notice if you look at well, it will won't be clear here, But if we were to, for example, pull up a This is interesting, actually have to.

  • This is a different version of a solitary looks like.

  • Let me find an image where they have cars that are already laid out.

  • For example, um let's see solitaire.

  • That's a solitary in progress.

  • So here, for example, you can see that they have things shifted a little bit.

  • It's kind of it's kind of mirrored, not mirrored, but flipped sort of vertically towards the right.

  • Um oh, it's along a vertical flipping point, its foot horizontally.

  • But you can see that the winning piles on the right side here knows that there's an ace here.

  • So this is the spades winning pile.

  • This is the hearts winning pile.

  • You can see that there's a two there, which means somebody already laid an ace and then a two.

  • But they're not being rendered vertically down there, not sort of like they don't have this cascade not cascading effect, but sort of this shifted offset sort of rendering effect that the piles the tableaus have on them right?

  • All of these are sort of rendered vertically, such that you can see them, the cards that are directly below any given card, and this is useful because we care about that information.

  • We want to ensure that we keep everything in a particular order that it's off suited.

  • Uh, these we don't care about.

  • We know we can.

  • We already know always that we have the, uh, the all of the space here, all of the hearts here, diamonds clubs.

  • However it's ordered.

  • So we will need to change our rendering logic from both of those use cases.

  • This particular area up top is going to probably implement a.

  • We might be able to reuse the debt class, but you know, semantics is not.

  • That's not accurate.

  • So a card pile probably is accurate.

  • We might be able to just use it for that and then use parenting for everything else.

  • And so that's probably what I'm inclined to.

  • D'oh!

  • Um, so the card piles will be used for the winning piles.

  • It makes more sense, probably at that point that then just call it a winning pile, right?

  • So rather than having an overly generic class, since we know that we probably won't use car piles for the other areas of our of our, um of our game board, we don't necessarily need to distinguish between the different piles.

  • So we'll sort of write in winning Powell right now.

  • We'll come back to it later.

  • We'll worry about it later.

  • In the meantime, what I do care about like I said is laying out all of the board and then testing our interactions testing, parenting, making sure that's all working so that we can start clicking and dragging cards in the right locations.

  • So back to the card class, which we're looking at a pier, we have a parent that's gonna be sort of kept within that class.

  • So this will refer to any of the card.

  • This will refer to a car directly above another card in the context of solider.

  • And actually, let me see, the parents are actually gonna be rendered below.

  • So the child cards, like so ate here is a child of nine.

  • So nine s 08 has a reference to nine as its parent, right nine has a reference to 10 as its parent.

  • 10.

  • As a reference to Jack.

  • Jack has weapons to queen and queen as reference to King as its parent.

  • And by moving Queen right, we will sever that parent child relationship, which is an important thing we need to do so that they don't get rendered or the king doesn't follow the queen.

  • We'll sever the relationship between the king and the Queen, and then we will make sure that all of the Children referred to their parents for their position.

  • So if the eight is saying, make my position my parents position make If the nine is saying, make my position my parents position, et cetera.

  • But with shift with a shift, obviously, like 15 pixels.

  • By moving just the parent, we will effectively move every single child as well.

  • So this is nice.

  • This this is a very simple way I think of looking at the problem.

  • So the self up parent is gonna be nil right now.

  • We're gonna worry about that.

  • In the meantime, let's go to our deck class, and then I'm going to say rather not deck class.

  • Sorry.

  • Game board class in here.

  • What I'm gonna do is I'm going to store, actually.

  • Already sort of sketched out last time.

  • We have seven tableaus here on, and so I'm just going to, um, shorthand right now.

  • I think I'm just going thio do this.

  • Right.

  • So I have one one.

  • Um, Well, actually, no.

  • Sorry.

  • Uh, we're gonna have seven tableaus like this.

  • These are empty tables.

  • So we have 1234567 and we can We could probably do this algorithmic, Lee.

  • So we'll consider doing that as well.

  • But just a sketch it out so we know what we're Look, we're doing crazy Fluke a guys, how are you tonight?

  • And Syrup says hi, everyone.

  • Hello.

  • Um, we're going to sketch out the layup of our tableaus right here.

  • So the first tableau, remember for looking left to right in the first temple was going to start with one card, so I could just say, um, actually, what we can do is I can say self dot deck, and then I want to draw a card, right?

  • That's effectively.

  • What?

  • What is going to look like?

  • And then we're gonna do it two times here, three times here for 56 and seven.

  • All of those cards are going to be faced down.

  • They need to be face down by default.

  • Except for the last card.

  • The the, uh, well, end up being the ultimate child of that stack, that child will be face up.

  • So this is essentially what is gonna look like in, uh, what we'll end up.

  • It'll also look like for the second pile, for example, of something like this right now.

  • Um, self dot deck.

  • Sorry.

  • Called itself Don't draw.

  • Should be self dot Deck and self dot deck draw.

  • It looked like this, and it'll sort of ADM.

  • Or and more and more and more Marcus remember going 1234567 cards.

  • So clearly this is going to look a little bit bulky.

  • We can do this in a loop a little bit more effectively down here.

  • So I could say, for I equals one until on.

  • And we're just going to again at here, too.

  • Good design.

  • I'm going to say, uh, here will say num tableaus is equal to seven.

  • So back to the game board from one until numb tableaus do Tableau is kind of a tricky word.

  • And again, last time I remember V s code is having issues with little formatting.

  • So if you're using V s Co with the newest version my apologies, it's hurting me as well.

  • I should probably have not updated, but alas, I did for from one of the number of tableaus were effectively gonna do what's in this, uh, this call right here.

  • I can say self dot tableaus.

  • Um uh uh Missy well, the table dot insert into self dot tableaus a new table.

  • And then what I'm gonna do is I'm gonna say four j gets one until I Because there's one card for every row there.

  • Seven rose, seven columns.

  • Sorry.

  • And each column has I cards, right?

  • Call him.

  • One has one card calling to s two cards called three has three cards s.

  • So therefore, we have another loop that's just gonna go up until I and draw that number of cards and put it in the right position in the in our tableaus in that particular tableau.

  • Right.

  • So I can say for John, for Jay is one until I I'm going to table dot insert into self dot tableaus at i self dot deck draw.

  • I can delete this right here.

  • We'll have to do it first to say self that top blows is equal to an empty table, which is gonna become a to D table here pretty soon.

  • And then we'll just say populate all tableaus with starting cards and down here in the draw carrying the render function.

  • What I want to dio is I want to render so that we know that this is working.

  • I want to render all my tableaus so I can say, for I is equal to and actually need to figure out where we started.

  • Our, uh, are actual grid indices, sir.

  • First of all, let's make sure that that runs.

  • So let's go ahead and do that.

  • It did not.

  • So Oh, we didn't implement the actual draw function in our deck.

  • So you need to do that.

  • So over in deck, I'm going to say so.

  • Sorry.

  • Function, deck, draw.

  • And what this is gonna do is returned a card from the deck and remove it because we want to draw a card from the deck.

  • But we also wanted to not be in the deck after we draw it.

  • Because obviously, if we draw card, but we keep it in there, we just return a copy of it.

  • Well, then our numbers are gonna be skewed.

  • We're not going to do with 52 cards.

  • We're gonna be dealing with infinite cards at that point.

  • So it's not gonna work.

  • Blue Booker says a to D table, make three D solitary stacked the cards in three dimensions, always with the good ideas Blue Book or keeping coming, that's Ah, That would actually be pretty cool, though.

  • I'm not gonna lie.

  • Be interested to see how that would actually be implemented.

  • I personally am not sure.

  • Um, Fan Mogi a 21 Georgie Law lay and see Marie to have a very low font size on this monitor.

  • I cannot read that to save my life.

  • CMR l j r j Thank you so much for fallen Georgie Law.

  • Um, crazy fuck.

  • The stream started for long.

  • Uh, this has way, haven't we?

  • Haven't been doing this particular stream for too long, but we did do a part one.

  • So we are progressed a bit beyond just the very beginning of a love to the application.

  • So if you haven't checked up solitary part one highly recommend watching the first part so you can see how we built a deck, how he built our game board, how we parsed ours, texture.

  • And we did a bunch of other things.

  • Um, this particular instance builds upon all of that source could weaken.

  • You can catch that on youtube dot com slash CS 50.

  • Look at our, um, our twitch playlist.

  • And also in twitch.

  • We have the VOD still up at the time of this recording.

  • It may not be on a time you're watching us in the future.

  • Okay, so we have our deck, our debt class with a draw.

  • Functional need implements.

  • We can actually get a card from the deck and then remove it from the deck.

  • So what I'm gonna do is I'm going to say local card is equal to and actually ran into this issue before.

  • So what?

  • I think what we need to do is make sure that we're making a copy of it.

  • So I'm going to say local, uh, card from deck is equal to and actually think there's a There's a copy function, but it might work funky with classes.

  • So we're just going to copy the card effectively on, then remove it from the deck because all we're effectively doing if we recall, is just storing a, um, a face and a suit.

  • Right.

  • Uh, I got that right.

  • Yeah.

  • A face value and a suit.

  • One of four values.

  • That's all we really care about.

  • So I'm gonna say card from deck is gonna be equal to self dot cards at math out random number of, uh, self dot cards.

  • So remember, the number is the length of the table.

  • So if you have 52 cards, give us number 52.

  • If our deck is only of size 40 or 30 it's gonna give us that number.

  • And so we get a proper number between one and the upper bound of our deck, which is important.

  • Let me just make sure that it is indeed self that cards.

  • I'm going to say local card to return is equal to a card that's gonna have card from dec dot face.

  • I think this is right face and suit.

  • Yep.

  • Um, and then card from dac dot vow.

  • Wait, what did I call it?

  • A suit?

  • I've been having a hard time keeping up with suit and face and value all these words that I am very bad about remembering.

  • But now what we can do is we can say, um actually, what we also need to do we need to store index.

  • So, um, card index is gonna be equal to this value right here.

  • Gonna replace that with card index.

  • I'm going to do that.

  • And then I'm going to say self dot cards at Card Index is equal to new, Actually better would be table dot remove self dot cards at Card Index, which I think underneath the hood just does do a new assignment.

  • Just assigns it to Nils to that way, because in lieu, if you have a nil index in your table, it effectively just condenses the table back together.

  • If I'm remembering correctly and so table don't remove effectively, just does that exact thing.

  • But we want as well just do.

  • What's more conventional.

  • I think table don't remove self dot cards at card index.

  • So if we drew a card in the middle of the deck, the deck gets sort of compressed inwards to accommodate that.

  • And now it's no longer 52 cards long.

  • It's 51 cards long, and what I can do then is like in return our card to return.

  • So now we have our new card, that replacing somewhere in our game.

  • We don't care where it is, But not only do we have a card that we copied from our deck, we removed it, and so now we're preserving sort of the gameplay mechanic of drawing a card from the deck very important thing to consider.

  • If we didn't do it this way, we would have infinite cards which would not be ideal.

  • Or it would have bugs with yeah, signing cards.

  • Two nil in our deck and them being new and all sorts of places.

  • Cool.

  • So our game board is the next place we need to do this.

  • All right?

  • What we're doing is we're testing, right?

  • So now what I want to do is I want to draw all of these cards that we've just allocated to our seven tableaus.

  • So these are the seven tableaus I want to draw.

  • My remember, we have seven tables now that fit those tableaus.

  • I wanna draw one card, two cards, three cards, four cards.

  • You're looking at it in reverse direction because of its flip.

  • Because of the camera.

  • One car to car streetcars, four cards.

  • We're gonna do it that way.

  • And so, uh, generate tableaus.

  • I don't think Oh, you know what I was gonna do?

  • This is gonna be the generate tableaus function so self generate tableaus.

  • And then I can just copy and paste that into this empty function which we must have written last time because I don't think we wrote it this time.

  • I think we wrote this in anticipation of what we needed to do for the next dream.

  • So now we have a generate tableaus function.

  • We sort of have shrunk the size of our constructor.

  • This is our constructor.

  • We don't want too much code in here.

  • This is where you know the object.

  • It's in Stan.

  • She ate it.

  • Their all of our values get initialized.

  • Having a bunch of logic and here kind of bloated, makes it hard to keep track of what's going on.

  • So we just made a function instead.

  • So let's actually draw each individual tableau and what we're actually doing, that is we're doing it here, right?

  • We have a fun way.

  • We don't have a function yet, but we do have seven rectangle calls that are effectively functioning similarly to that.

  • And so I still want the grid to draw in case I move cards away from, you know, the tableaus.

  • Um, just thinking it had a little bit.

  • Yeah, So this is how we're going to need it, and I think that should be fine.

  • Here were effectively going to check for cause that we're gonna have tableaus.

  • We're gonna have cards in those positions.

  • These seven tables are where we're always going to store the cards no matter what.

  • Even if we move cards around between tableaus, we're not actually storing card pile objects and mixing and matching those.

  • And I actually think that would get relatively complicated and kind of hard to maintain our d'oh hard to reason about a little bit.

  • So we're just going to draw each tableaux individually and all of its cards And those parent child relationships that we talked about earlier on are going to help us make sure everything looks and functions in the same way.

  • Um, so what I'm going to do is four eye is equal to one until numb tableaus.

  • D'oh!

  • So we're just gonna get a rate iterated over and draw cards in tableaus.

  • Tableau grid marker is just to differentiate them to be more s'more explicit about were actually drawing.

  • So I'm going to again.

  • We need a nested loop within this over iterating over our seven top blows.

  • But we also reiterate over the cards and the top blows to actually draw things out.

  • So I'm going to say Forge A is equal to one until tableaus I, um, number of tableaus I do.

  • And because the tableau, um, tableaus that I's going to have a length of cars that we need to render and this will This will change over time, and it's gonna get a little more complicated when we actually need to draw them in the right order with the parenting.

  • But this should still be doable.

  • Things should still we'll have it structured, ideally, such that, um, will preserve the rendering order so that we can illiterate over the cards in the right order and draw everything out on the parent child relationship will be preserved.

  • Ah, whip straight.

  • 23 says hello.

  • That's Nate shot tonight.

  • Thank you for joining our stream.

  • Um, so here we can say so.

  • We have ah place here.

  • So these are actual individual tableau locations, and there's a mathematical operation that we're playing here, which is 10 plus 80 times.

  • I minus one in this case s O.

  • C.

  • 10 plus 80 times.

  • I'm minus one.

  • So eyes one minus one is 0 80 times zero is zero plus 10 is 10.

  • But, you know, plus one is two times one is 90 and then 1 72 53 30 So just shifting everything.

  • About 80 pixels.

  • So we'll maintain that relationship here as well.

  • So we'll say, um and we car does have a render function.

  • Correct?

  • It does so well say, uh, tableaus.

  • I render at 10 plus 80 times uh, J r.

  • I minus one and at why Value 1 60 these should be.

  • This is kind of temporary variable values because I don't necessarily know where I want the card grid to be drawn tableaus to be drawn eventually.

  • Right now, we're just kind of getting everything in place.

  • We can easily add a margin value and shift all of this and change our our game size that it's a little bit maybe a little bit closer up.

  • So things look a little bit more interesting.

  • It's a little bit zoomed out now because the textures are kind of small.

  • Um, so we'll worry about that in time right now, but just get the the logic correct, and then let's let's figure out the values that we want at a later time and then get everything rendering perfectly also shadows to Andre thank you very much for joining the stream.

  • And Nate, don't be sorry that you're late.

  • It's okay.

  • You can definitely watch the Baden scroll back and watch on YouTube at any point.

  • Um, so this should work now.

  • The only problem is we want to draw all of our cards.

  • But if we're drawing them all the same x of drawing him all the same wide value, we're not gonna preserve their stacking right where they're all gonna be directly on top of each other, which doesn't help us.

  • So this 1 60 we could actually add, maybe plus 10 times J minus one, Right?

  • Because of red J cards.

  • Right for it.

  • Now, if J is one that will just draw it the right just, you know, one money's 10 time standing.

  • Zero.

  • So it'll just shifted by zero pixels.

  • But if we're at J one or rather J two and we minus one more than its one times 10 and then we'll add one will have 10 pixels to our drawing and then 20 and in 30.

  • And so that will give us that stacking order as we draw.

  • Let's do that.

  • Um, Ellis actually see If this is working, it is not, uh, Global tableaus, which is a game board line 58 which, yes, self dot tableaus and self dot tableaus at Let's Try that, uh, method Render and No Value Game Board 59.

  • Interesting.

  • So self taught tableaus at I at this point is supposed to be a card, and this is a problem with dynamic programming languages.

  • It's not always clear that you're gonna have the right data in the right place when you run your application.

  • If using a statically type language like Java, um, then it can actually check to make sure that you're putting things in the right container.

  • But if you're not doing that, if you're using Lulu or python or Ruby or some other languages dynamically typed, then you're gonna kind of have to cross your fingers.

  • Sometimes.

  • Just make sure your logic is sound, which mine always isn't, as we can clearly see here.

  • So at Line 59 attempt to call Method render, which is a mill value, so card is no.

  • At least what we assume to be a card in self dot tableaus is new, so let's see whether our logic is sound.

  • So we have game board generate tableaus from one until the number of tableau is we're inserting.

  • Ah, right.

  • So self that tableaus at I actually right, cause needs to be I j right, Because we're rendering.

  • We were trying to render our entire tableau table.

  • At that point, we need to actually index.

  • Remember, we're storing a table of tables on each table.

  • Each nested table contains cards, right?

  • So that's what we needed to do.

  • We need to index into the right tableau, and then we need to get the right card from the tableau, which now it's not rendering anything, but at least our logic is sound.

  • Um, let's figure out why that might be That's Oh, you know why?

  • Because they're not being assigned.

  • Um, Well, actually, they are being given an external Why, that's what this is here.

  • Right?

  • Um see what?

  • Why is that not working?

  • That is odd.

  • Um, now we didn't make self that hidden true diddly car.

  • Let's see, the render function is so card back, right?

  • Okay.

  • And we want the car to be hidden on.

  • Well, we don't want them to be hidden unnecessarily.

  • We're going to do the next part of what we'r

All right.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

SOLITAIRE PART 2!- CS50 on Twitch、EP.41 (SOLITAIRE PART 2! - CS50 on Twitch, EP. 41)

  • 0 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語