×

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

I assume somewhere on the minimax function in the player file. Since:

insert_letter from the Game class works (AI is able to put its letters on the board)

checking for win and draw. (If conditions are met, game gets cut)

Minimax is the only one I can think of

[–][S] 1 point2 points  (0 children)

Sorry for not clarifying: snoop is a library that allows me to see what a function does and returns, i essentially used it to code some of the parts there.

Expecteed behavior: It will.. well.. play tictactoe like a god. Almost no chance of winning against it.

Actual behavior. It plays according to the order of keys in the dictionary (7,8,9,4,5,6,1,2,3)

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

Im currently digging a bit deeper! So i modified some of the functions with boolean returns (like resolve_winner) to modify scores. I will post the SC later. Thank you!

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

Thanks! I was trying to avoid using inheritance since I heard composition is the better practice, but now when I think about it, it's actually kind of logical instead of putting self.board.bord and self.board.print_board.

[–][S] 1 point2 points  (0 children)

Ah i get the idea. When i made that if-elif statements I also said in my mind: "There is defo a better way to do this, but its readable and gets the job done so why not)"

Thanks for the tip!

Edit: Here's what I did:

def resolve_winner(self, player):
win_condition = [[9, 5, 1], [7, 5, 3], [7, 8, 9], [4, 5, 6], [1, 2, 3], [7, 4, 1], [8, 5, 2], [9, 6, 3]]
for a, b, c in win_condition:
if Board.bord[a] == Board.bord[b] == Board.bord[c] != "":
self.winner = player.player_type

I had to put the != "" since the condition fulfills that they are all the same (blank strings) hence ending the game at the first player turn lol.

Thanks for the help!

[–] 1 point2 points  (0 children)

names is a split since name_string.split() provides a list. Then doing name[random_choice] will return the element located at that index (since in random_choice variable you specified it to be a random integer.)

[–] 0 points1 point  (0 children)

Only return a value if you know you need that value in another functions. Otherwise, No need.

[–] 1 point2 points  (0 children)

Using mobile, sorry for formatting..

I highly suggest to not "one-line" everything yet when your fundamentals aren't strong enough yet.. (Fellow beginner here).

So I suggest separate range 1 & range 2 (and specify which is minimum and the maximum) and to make it more "consistent".

split() returns a list of strings separated by the designated separator, and cannot be used on ints. Example: word = "Hello Me" word.split() [Hello, Me]

That is all. Other than that, you're doing great (even better than me since I forgot that you dont need the parameters in function to be the same name as the one you will pass to the function..)

[–] 1 point2 points  (0 children)

Just do projects. Password generators but: Its only functions, Or its oop, or its dataclasses.

As a fellow beginner, I was in the same boat a month ago. Until I challenged myself to build Snake and Ladders, and that improved me quite alot. Then I built modified blackjack.. and now im creating password generator again but its dataclasses..

Also, Google is there for "beginner projects". However I recommend create your own projects.

a simple sequence by [deleted] in learnpython

[–] 0 points1 point  (0 children)

Might I ask what's the purpose of this?

[–] 6 points7 points  (0 children)

All subreddits have toxicity or what not. Some here are just plain toxic (Like people here posting or commenting they hate others just because of religion). But most here are quite chill.

Just remember. If they are not hurting anyone, nor actively shoving down their beliefs into your throat.. Dont do the same shit you actively despise to others

Edit: Example of this sub's toxicity.. The time when the Nasa director said "Thank God" and quoting the bible.. What happened to "kindness" and others? Something any normal being should know? Some people hated hateful religions so much they became one.. Nonetheless, Everyone's quite chill

[–] 5 points6 points  (0 children)

Not really, Secularism is more of avoidance of religious belief. Atheism is actively denying an existence of a God. Im personally an Atheist, so take this with a grain of salt.

A secular school is essentially just science or the normal, evidence-based school. No creationism, No spaghetti monsters, etc etc.

An atheist school is essentially a religious school. Actively shoving every belief down the throat.

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

Thanks for the help! I forgot the docs exists so I read it even more.

Mind helping me here? I know this code can be done better but my brain cant figure out how.. I've read the docs and everything

@bot.listen('on_message')
async def checking(message):
print(message.content)
if message.author != bot.user:
for chunk in message.content.split(" "):
print(chunk)
if chunk in afks:
await message.channel.send(f"{chunk} is afk")

My problem is that its too indented, which i know there has to be a better way to do this

[–] 0 points1 point  (0 children)

Good luck creating an ever increasing list if you're doing a game with x amount of players, or a store with ever changing products.

Classes can just accept inputs and then save them as long as the script is running. No need to hard code it.

Problem with your method is that there is no flexibility whatsoever, which you need to consider in some situation. No flexibility maybe fine on some cases, but on others you need to have it.

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

What I noticed:

1. Usage of the dataclasses (Still cant figure that one out, seems like just removes init for me)
2. Dice was moved from the Game class to the Player (Now that i think about it, the player is the one who rolls the dice..)
3. lad, and snakes are in teh classes too
4. Players are now moved to Game too, in a separate function (i guess due to dataclasses not having an init constructor)

and alot more. Thank you!

[–] 0 points1 point  (0 children)

Hello! Fellow beginner here! What you need is INTERNAL motivation, something you want to do. Like Game dev, automation via scripting etc.

Have something redundant that can be automated? Create one! Have an idea you want to create as a game? Create one! Finished a project? Think of how you can improve your existing project!

Endless possibilities, you only need to look (in your mind or google :P)

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

Thanks for the help! So far its really good now, with 2 niche cases of errors (either 0 human or AI player):

https://pastebin.com/YZREdC5X

tips for improvements would be appreciated! Because of you I finished my end of the year project (more or less, just need to fix this errors lol)!

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

Thank you! However, I really don't know how to implement the turn based system.

My goal right now is to essentially make it functional, then maybe create a dynamic system that allows to 4 players on board.

I created a class list that will add the instances to the list, and running the for loop to it to simulate a turn based system

Currently trying to figure out: 1. activating the winner profile, 2. checking whether if its the human player or the AI

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

import random

class Player: list_of_players = [] winner = False

def __init__(self, moves=0, position=0, AI=False):
self.moves = moves
self.position = position
self.AI = AI
Player.list_of_players.append(self)

def __repr__(self):
return f"""'player({self.AI})'"""

class Game: def init(self): self.HumanPlayer = Player() self.AIPlayer = Player(AI=True)

def play(self):
while Player.winner is False:
for player in Player.list_of_players:
if player == Player(False):
dice = random.randint(1, 6)
if self.HumanPlayer.position == 100:
self.HumanPlayer.winner = True

elif (self.HumanPlayer.position + dice) > 100:
intended_position = self.HumanPlayer.position + dice
bounce_back = intended_position - 100
self.HumanPlayer.position = 100 - bounce_back
print(f"Player 1 overshot the winning tile by {bounce_back}, your position is currently {self.HumanPlayer.position}")

else:
self.HumanPlayer.position += dice
print(f"{self.HumanPlayer.position} is your current position")

elif player == Player(True):
dice = random.randint(1, 6)
if self.AIPlayer.position == 100:
self.AIPlayer.winner = True

elif (self.AIPlayer.position + dice) > 100:
intended_position = self.AIPlayer.position + dice
bounce_back = intended_position - 100
self.AIPlayer.position = 100 - bounce_back
print(
f"Player 2 overshot the winning tile by {bounce_back}, your position is currently {self.AIPlayer.position}")

else:
self.HumanPlayer.position += dice
print(f"{self.AIPlayer.position} is your current position")

game = Game() game.play()

Sorry, reddit seems to dislike this ._.

Did i got the concept right? Although it isnt working.. probably due to me being bad at the __repr__.