I use or-tools to optimize my fantasy baseball team. My setup very much resembles the program described here. The only difference in my particular case is that players can actually be eligible for a number of different positions. So, I end up with 1 player in a list for a specific position type, and the same player in another list for another position type. I am trying to avoid having the solver select the same player for multiple positions (which wouldn't be realistic).
Is there any way to modify the aforementioned program to constrain the use of a player to a single position even while they are technically eligible for many? Please let me know if I can clarify any further & thanks for your input.
I'm writing a code for blackjack, using the classes and other oops concept. Currently I'm stuck on how to decide what classes it will have.
Following are the rules of blackjack:
1.Create a deck of 52 cards
2.Shuffle the deck
3.Ask the Player for their bet
4.Make sure that the Player’s bet does not exceed their available chips
5.Deal two cards to the Dealer and two cards to the Player
6.Show only one of the Dealer’s cards, the other remains hidden
7.Show both of the Player’s cards
8.Ask the Player if they wish to Hit, and take another card
9.If the Player’s hand doesn’t Bust (go over 21), ask if they’d like to Hit again.
10.If a Player Stands, play the Dealer’s hand. The dealer will always Hit until the Dealer’s value meets or exceeds 17
11.Determine the winner and adjust the Player’s chips accordingly
12.Ask the Player if they’d like to play again
I'm new to coding and oops, kindly help
NOTE: this is not a homework problem, as there are many solution on github, which i can copy submit if required. I Just want to learn oops and classes. I don't seek a solution, I'm seeking a correct thought process
It is a difficult process; usually, the first step is to identify the nouns in the description of the project, that gives you a starting point from where to think about the shape you will give to your code, and how you see these objects interacting.
From your description, we could list the following nouns:
Deck, Player, Bet, Chips, Cards, Dealer, Hand, Winner, Player’s stash.
They may, or may not represent a useful object in your representation of blackjack. Some may be obvious objects you need now (Deck, Card, Hand, Player, Dealer); some may be combined (Chip, Bet, Stash); some may not be needed in a modest application (Winner, Bet, Stash), and replaced by data structures, like Lists, Vectors, HashTables, etc.
Create a deck of 52 cards
Shuffle the deck
Ask the Player for their bet
Make sure that the Player’s bet does not exceed their available chips
Deal two cards to the Dealer and two cards to the Player
Show only one of the Dealer’s cards, the other remains hidden
Show both of the Player’s cards
Ask the Player if they wish to Hit, and take another card
If the Player’s hand doesn’t Bust (go over 21), ask if they’d like to Hit again.
If a Player Stands, play the Dealer’s hand. The dealer will always Hit until the Dealer’s value meets or exceeds 17
Determine the winner and adjust the Player’s stash accordingly
Ask the Player if they’d like to play again
You should think in any object you will need in your game, and think about the attributes and actions they will make, for example the Card should have a suit and a value, these are the card attributes. The deck should contain every card and be able to shuffle the cards, so create a method inside your Deck Class that can do this function.
Here i will leave a link so you can have a better understanding of OOP in python.
https://realpython.com/python3-object-oriented-programming/
I'm working on a quiz for my exam in computer science. I'm relatively new to the program, in the sense that I know all of the basics, but I am on the point where I want to expand my knowledge. One way I want to do this is by adding a Leaderboard system. The user gets a number of points, and then the program checks in a text file that has other high scores in it, and adds the user to it. It then prints out the leaderboard. This means that I'm going to have to use some sort of operations to determine whether the user's score is higher or lower than another score in the file, and then delete the score it is higher than and replace it. Any idea on how to do this? I'm completely stuck.
Try Pseudeocode and work through steps.
Get Score
Compare Score
Add Score
You have to think like a computer and break all the way down. At each step think about how do I tell the computer to do that. Once you have all that look at what you have done and remember DRY -> Don't Repeat Yourself. Your coding will go much faster.
We are a group of 20 people and we like to go play 2 vs 2 tennis matches. Each of us plays one match each round and we do 5 rounds in total, so everyone plays 5 matches. Matches have two restrictions:
Everyone has a different level (from 1 to 5), so the matches must be balanced: two players with levels 5 and 5 shoulnd't be matched with two levels 1. So between the two teams, the difference in level must be lower or equal to 1.5.
Ej.: level 1.5 and level 2 vs level 2 and level 2.5. The difference in level between teams is 1 so the match is accepted.
If two players play together in one match, they must not play toghether again in the following rounds.
I managed to create a python script that does the specified above, but it takes about 20 minutes to finish depending on the level of the people :/. What I do is shuffle the list with every one in it, break it into 5 lists of 4 people, check if conditions are satisfied and repeat for every round.
I tried modeling the problem to solve it with linear programming (LP) but I don't know which is my function to optimize to begin with... Any ideas on how to do this with or without LP?
Thanks in advance!
You could use a dummy objective or even try to minimize the max of the difference in levels.
My MIP model is not completely trivial, but it solves quite fast (about a second or so using a commercial solver).
The results look ok at first sight:
I assumed two players cannot be in the same team more than once. I.e. not just in the same game. That is in my case you can play against another player more than once.
A more complex example can be found here.
I've written the MCTS AI in python and now, I'm trying to improve upon its first iteration. I've been told that I need to improve my rollout function. The purpose of the AI is to play the game of dots and boxes.
Right now, after receiving the state of the game, the rollout just plays out the remaining of the game randomely.
Rollout:
while not state.is_terminal:
state.apply_move(choice(state.legal_moves))
I was wondering how can I improve the AI by altering the rollout function?
In dots an boxes random play is probably pretty poor because it will (1) miss opportunities to fill boxes and (2) give opportunities for opponents to fill boxes, both of which make the playouts less like real play.
So, the simplest change would be to order the moves in the playout. First, take a random move that fills a box, if possible. Second, take a random move that doesn't give the opponent a chance to fill a box. Finally, give the opponent an opportunity to fill a box. (But, here you might want to select a move that gives the opponent the smallest region to fill with high probability.)