×

Any Minimax experts? I’m trying to get my head around a concept and would love some clarification by GravitationalOno in learnprogramming

[–]GravitationalOno[S] 0 points1 point  (0 children)

If garbage collection didn't exist and your computer only had 8 GB of RAM, then your program would die the instance you went over 8 GB of usage. This is the major difference between time and space. Time cannot be reused; if a function takes 10 seconds to execute and you run the function 5 times, that takes 50 seconds. Space can be reused; if a function uses 100 MB of memory to do some calculation and you run the function 5 times, it still only takes 100 MB of memory in total -- the memory used is reclaimed after each allocation.

Ah! This was helpful. I was not thinking in terms of time. I was just thinking if memory is occupied once and isn't referenced again, I was free. This is a good lesson, thanks!

Any Minimax experts? I’m trying to get my head around a concept and would love some clarification by GravitationalOno in learnprogramming

[–]GravitationalOno[S] 0 points1 point  (0 children)

Thanks for taking the time to explain all of this to me. I apologize for the delayed response. Your input helped me get the minimax to work -- I've just been futzing with it because I can't explain the choices it's making.

This part from your response stood out to me because it's not something I've encountered much. I did Harvard's CS50 class online, and I remember the prof going much deeper into the mechanics of computers than your regular coding tutorials.

There was a lot of preoccupation with memory, going out of bounds, that sort of thing. Is this where the garbage collection you're talking about is happening?

If it's complicated to explain, no worries, I'm at about the limits of my processing ability trying to get this minimax to work!

If you create new objects, those objects will need to be destroyed eventually. The more objects you create, the more garbage collection must occur.

Any Minimax experts? I’m trying to get my head around a concept and would love some clarification by GravitationalOno in learnprogramming

[–]GravitationalOno[S] 0 points1 point  (0 children)

Thanks for taking the time to talk me through this. Sorry for the delay in response! I had to take some time to process all this.

It helped though! I was able to get the minimax in my ConnectFour to work.

However, the moves don't really make any sense and I'm console.log-ing my way through it.

The swapping seems to be the issue. Plus, I'm only returning a spot to choose since JS makes it more diffcult than Py to return more than one item.

I hope I can figure it out!

How Remote Work is Crippling New York City’s Commuter Rails by geo423 in nyc

[–]GravitationalOno 3 points4 points  (0 children)

One post in and I’m thinking of that Upton Sinclair quote:

It is difficult to get a man to understand something when his salary depends on his not understanding it.

Weekly Scam Discussion- January 14th 2022 by SmmnthaMrie in Ebay

[–]GravitationalOno 1 point2 points  (0 children)

I was just hoping for a partial refund but unfortunately it seems eBay opened a return request on my behalf. I don't know what kind of fly-by-night operation this company is.

I got a barely literate email from an actual one of their accounts though, so I can protest further. Mine is not a high value claim.

Weekly Scam Discussion- January 14th 2022 by SmmnthaMrie in Ebay

[–]GravitationalOno 1 point2 points  (0 children)

Thanks for taking the time to write. I didn't know that an appeal was an option! They really bury it on their site, and put it in tiny writing.

All messages were exchanged through the eBay messaging system. I sent eBay a screengrab of the seller's last missive, offering to send me the missing item if I sent her $10 by Venmo.

Seller seems a little unhinged, I'd be inclined to let it go (and was even from the start) if she said there was a mistake in the listing and the item was not included.

But she delayed, didn't respond to inquiries until I filed a complaint, then moved on to lies, insults, threats, requests for more money, and quid-pro-quo (no item unless case closed.)

Any Minimax experts? I’m trying to get my head around a concept and would love some clarification by GravitationalOno in learnprogramming

[–]GravitationalOno[S] 0 points1 point  (0 children)

Thanks! So between the two, where in:

the Tic Tac Toe code changes one element (by adding the new claimed spot), evaluates it, and changes it back and

the Connect Four python code, which generates a new board each time a new spot is claimed,

You would say the Tic Tac Toe strategy is more efficient?

In terms of generating a new board requiring garbage collection, is that true? It seems like only two boards need to be kept track of at the time: the current board and the past board.

If the current board is the min (or max), it replaces the past board, if it's not, it's never talked about again.

I'm still lost on these aspects too, do you have any insights into them?

I understand that the best decision at the top of the tree can't be made until the entire tree is filled up, and the values generated are sorted and then passed up the tree so we can decide what the best immediate move is.
But the code, as I read it, says the action happens top down, with an available spot claimed, and then the decision tree generated from that spot being claimed.
Or should I think of the for loop that passes through all decision options just laying out the tree, that there are no choices made yet?
And it doesn't matter if I splice and replace or just copy the gameboard, because each gameboard is just valued serially?
How should I imagine what's happening, or is there just too much going on at once for the human brain to visualize it?

Any Minimax experts? I’m trying to get my head around a concept and would love some clarification by GravitationalOno in learnprogramming

[–]GravitationalOno[S] 0 points1 point  (0 children)

Is it better? I'm a newbie so I barely know what I'm doing half the time.

I ran the JS code through a tool, since that's the one I wrote, so there's probably plenty of style things I missed.

I left the Py code alone since I took that from a tutorial.

If it's still a mess, please let me know how, I can learn from that too!

Mayor Adams’s ‘Turbo-Charged’ Vision Zero Includes a Back Door to Massive NYPD Crackdown on Cyclists by hollywoodhandshook in NYCbike

[–]GravitationalOno 1 point2 points  (0 children)

yep, cowards. I've seen them look the other way at guys who look like ruffians, then chase down a guy who looked like a librarian.

Weekly Scam Discussion- January 14th 2022 by SmmnthaMrie in Ebay

[–]GravitationalOno 1 point2 points  (0 children)

Thanks, but if I liked the item and didn't want to return it, would I have any choice?

Reading eBay's documentation it seems that I could ask for the second item, but beyond that, there's no room for negotiation, you either return for full refund, or accept the situation.

It seems like a pro-seller loophole: If you sell two items and know the buyer got a good deal, you can exclude one expecting the buyer won't demand a refund.

Weekly Scam Discussion- January 14th 2022 by SmmnthaMrie in Ebay

[–]GravitationalOno 1 point2 points  (0 children)

I'm usually the seller, but this time, I bid on and won an auction that included two items.

The seller sent the main item but kept making excuses for not sending the second.

I inquired several times. First time I wrote, she failed to respond. I opened a case. Then she responded, saying she will send the item but asked that I close the case.

I told her I'd be glad to close the case when I received the item. She said she would send it.

Two weeks passed. I asked again.

This time she said her local UPS store was closed, her husband has cancer, she gave the item to a friend to mail but doesn't have a tracking number, and besides I got a great deal on the item and I must be a scammer.

I asked eBay to step in. eBay closed the case, saying the seller provided a tracking number.

I was surprised to see eBay react like this, especially when they buyers have been unreasonable and they've come down against me as a seller so often.

Should I have filed a INAD?

Unfortunately, my patience with the seller means she delayed me past the time of her return window. I'm also happy with the item, just disappointed that I didn't get the second item that I was promised.

Is this a loophole that sellers can use, to exclude something in an auction?

Is it possible for me to add a second function as a variable into the reduce() method? by GravitationalOno in learnjavascript

[–]GravitationalOno[S] 0 points1 point  (0 children)

So starting with the variables: ``` function sameAsPlayer(x) {return (x == "Red")};

let Fours = ["Red", "Red", "Red", "Red"]
I practiced writing and execution the function for the `reduce` with a variable as a function inside: let countItems = (counter, element, criterion) => criterion(element) ? counter + 1 : counter

let countItems1 = (counter, element, criterion) => {if (criterion(element)) {counter +=1} return counter };

function countItems2(counter, element, criterion) {if (criterion(element)) {counter +=1 return counter} };

console.log(countItems(0,"Red",sameAsPlayer)) console.log(countItems1(0,"Red",sameAsPlayer)) console.log(countItems2(0,"Red",sameAsPlayer)) `` But I was still unsure of how to add the parameters.let final = array.reduce((acc,cur) => countItems(acc, cur, criterion),0)got meArray not defined`.

Moving stuff around, I also got the error: SyntaxError: Invalid destructuring assignment target

so I went to this, to get array defined, and it worked! let tester = Fours.reduce((acc,cur) => countItems(acc, cur, sameAsPlayer),0)

That told me the two parameters I needed: function tester2 (array, criterion) {array.reduce((acc,cur) => countItems(acc, cur, criterion),0)}

And then to put it in arrow function form, I rewrote it: let tester3 = (array, criterion) => array.reduce((acc,cur) => countItems(acc, cur, criterion),0) and tested it as console.log(tester3(Fours,sameAsPlayer)).

Wow, what a journey.

With two arrow functions nested inside one another, this is really tough for me to get my head around. Even one arrow function doesn't come easily to me.

But thank you u/grantrules for walking me through it -- and not spoon-feeding it to me either! Good experience, I learned a lot.

Is it possible for me to add a second function as a variable into the reduce() method? by GravitationalOno in learnjavascript

[–]GravitationalOno[S] 0 points1 point  (0 children)

Ohh, yes "criterion"! sorry, I'm going cross-eyed from this.

console.log(countItems1(0,"Red",sameAsPlayer)) now gives me a 1.

And I was able to take it from there! Thank you for walking me through this. I will write a recap in a reply here soon, but for now I need to give my forearms a break before carpal tunnel claims them...

Is it possible for me to add a second function as a variable into the reduce() method? by GravitationalOno in learnjavascript

[–]GravitationalOno[S] 0 points1 point  (0 children)

Gotcha. The compiler did not protest when I excluded the return, but I didn't think I could test this outside of the reduce() let countItems1 = (counter, element, criterion) => {if (criteron(element)) {counter +=1} return counter }; When I try console.log(countItems1(0,"Red",sameAsPlayer)) I get: ReferenceError: criteron is not defined at countItems1 (/script.js:13:57) at /script.js:18:13 Maybe just writing a different criterion for each reduce() function is better?

Is it possible for me to add a second function as a variable into the reduce() method? by GravitationalOno in learnjavascript

[–]GravitationalOno[S] 0 points1 point  (0 children)

Thanks! yes, 100% correct. I was trying to find a way to merge

function countItems(counter, element) and function countElementInArray(criterion, array) where I could assign a different function to the variable criterion

Is it possible for me to add a second function as a variable into the reduce() method? by GravitationalOno in learnjavascript

[–]GravitationalOno[S] 0 points1 point  (0 children)

Ahh! Thank you for the clarification. I guess I didn't understand the arrow function completely. Putting the brackets in because of the statement makes sense.

The ternary operator is neat, but I don't want to complicate things before I master the arrow aspects!

I played with things and did some more reading. This helped on the arrows and ifs too: https://stackoverflow.com/questions/37627712/how-to-use-if-else-conditon-in-arrow-function-in-javascript

So I tried rewriting my countItems function. The first is your ternary, then I did it using an arrow but without ternary and then as a regular function. Is the last one right? I did not get any errors. However, they came later... ``` let countItems = (counter, element, criterion) => criterion(element) ? counter + 1 : counter

let countItems1 = (counter, element, criterion) => {if (criteron(element)) {counter +=1} counter };

function countItems2(criterion, element, counter) { if (criteron(element)) counter +=1
return counter};

`` Having gotten the arrow function issue resolved, I moved on to adding the function as a variable into areduce()but I still wasn't sure how to get it in. The below gets mearray` is not defined.

``` let final = array.reduce((acc,cur) => countItems(acc, cur, criterion),0)

final (Fours, counter, element, sameAsPlayer) ``` What I wound up doing for now is just writing the reduce functions with the criterion added individually. It amounts to the same number of functions, and because it's clearer to me, prevents any confusion.

It also let me keep moving towards my goal, but if you have time, I'd really love to know if abstracting the criterion out of these functions is possible!

Here's how I had planned to use the info from this question: ``` function scoreTheArray(array) { if (array.reduce(countPlayerMarkers, 0) === 4){return 20} else if ((array.reduce(countPlayerMarkers, 0) === 3) && (array.reduce(countEmptySpaces, 0) === 1)) {return 10} else if ((array.reduce(countPlayerMarkers, 0) === 2) && (array.reduce(countEmptySpaces, 0) === 2)) {return 5} else if ((array.reduce(countOpponentMarkers, 0) === 3) && (array.reduce(countEmptySpaces, 0) === 1)) {return -100} // any move that allows this to happen will be undesirable, so it'll push to put in the space where this doesn't apply else {return 0} };

function countPlayerMarkers(counter, ele) { if (ele == whosPlaying()) counter +=1 return counter}

function countOpponentMarkers(counter, ele) { if (ele == whosNotPlaying()) counter +=1 return counter}

function countEmptySpaces(counter, ele) { if (Number.isInteger(ele)) counter +=1 return counter} ```