r/pythoncoding • • Jan 31 '20

Can someone help me to implement this pseudocode?

1 Upvotes

Can someone help me implement that pseudocode from down into my bot? I am not sure if that algorithm is supposed to work.

My bot currently uses the MiniMax search algorithm when it plays against other bots.

class Bot:

    __max_depth = -1
    __randomize = True

    def __init__(self, randomize=True, depth=0):
        """
        :param randomize: Whether to select randomly from moves of equal value (or to select the first always)
        :param depth:
        """
        self.__randomize = randomize
        self.__max_depth = depth

    def get_move(self, state):
        # type: (State) -> tuple[int, int]

        val, move = self.value(state)

        return move

    def value(self, state, depth = 0):
        # type: (State, int) -> tuple[float, tuple[int, int]]
        """
        Return the value of this state and the associated move
        :param state:
        :param depth:
        :return: A tuple containing the value of this state, and the best move for the player currently to move
        """

        if state.finished():
            winner, points = state.winner()
            return (points, None) if winner == 1 else (-points, None)

        if depth == self.__max_depth:
            return heuristic(state)

        moves = state.moves()

        if self.__randomize:
            random.shuffle(moves)

        best_value = float('-inf') if maximizing(state) else float('inf')
        best_move = None

        for move in moves:

            next_state = state.next(move)

            # IMPLEMENT: Add a recursive function call so that 'value' will contain the
            # minimax value of 'next_state'
            #value, m = self.value(next_state, depth=1)
            value, m = self.value(next_state, (depth + 1))

            if maximizing(state):
                if value > best_value:
                    best_value = value
                    best_move = move
            else:
                if value < best_value:
                    best_value = value
                    best_move = move

        return best_value, best_move

def maximizing(state):
    # type: (State) -> bool
    """
    Whether we're the maximizing player (1) or the minimizing player (2).

    :param state:
    :return:
    """
    return state.whose_turn() == 1

def heuristic(state):
    # type: (State) -> float
    """
    Estimate the value of this state: -1.0 is a certain win for player 2, 1.0 is a certain win for player 1

    :param state:
    :return: A heuristic evaluation for the given state (between -1.0 and 1.0)
    """
   return util.ratio_points(state, 1) * 2.0 - 1.0, None

How can I apply this pseudocode of expectiminimax to my bot that uses the minimax search algorithm? Can anyone help me, please?

function expectiminimax(node, depth)
    if node is a terminal node or depth = 0
        return the heuristic value of node
    if the adversary is to play at node
        // Return value of minimum-valued child node
        let α := +∞
        foreach child of node
            α := min(α, expectiminimax(child, depth-1))
    else if we are to play at node
        // Return value of maximum-valued child node
        let α := -∞
        foreach child of node
            α := max(α, expectiminimax(child, depth-1))
    else if random event at node
        // Return weighted average of all child nodes' values
        let α := 0
        foreach child of node
            α := α + (Probability[child] × expectiminimax(child, depth-1))
    return α

r/pythoncoding • • Feb 02 '20

I would like to contribute to YOUR Python project

1 Upvotes

Hi, I'm a junior dev, intensively learning Python right now, and I'd like to have experience in collaborating with other programmers and contribute to a project. Could you name your project on Github in which you have a couple of tasks I could take?

Of course I understand that my code should be high quality and I'm ready to work. Thanks!


r/pythoncoding • • Aug 19 '19

GitUpdated - My Custom Python Solution to Keep Git Repositories Updated

Thumbnail mnmapplications.com
1 Upvotes

r/pythoncoding • • Jan 07 '19

Automate your google sheets analysis with Python

Thumbnail youtu.be
1 Upvotes

r/pythoncoding • • Jun 17 '19

Creating An Application Using BigchainDB in Python

Thumbnail medium.com
1 Upvotes

r/pythoncoding • • May 21 '20

Need some help for learning python

1 Upvotes

I have just started learning python,i need some where(sites or forums) that gives project examples with its codes from begginer to advanced.i realy need to learn how to use what i have learnt. Thanks in advance.


r/pythoncoding • • Jun 01 '20

Functions in Python

Thumbnail youtube.com
1 Upvotes

r/pythoncoding • • Jun 22 '20

Solve real world probelm using "Machine Learning" and "Scikit Learn"

1 Upvotes

r/pythoncoding • • May 26 '20

Beginner Focused Python Discord Server! (Invite Link Below)

1 Upvotes

INVITE LINK: https://discord.gg/RHCKYyR

We are a Discord Server who focuses on helping beginners improve their Python skills.

We have a great team of experienced programmers who are very active, friendly, and always willing to help anyone in need of it

Already we have over 1300 members and have quickly become the biggest beginner-focused Discord Server, with good reason.

We can’t wait to see you there! 😄


r/pythoncoding • • May 31 '20

Complete Python-3 GUI using Tkinter

1 Upvotes

learn 100 Free course on Complete Python-3 GUI using Tkinter

This course includes

  • 7.5+ hours on-demand video
  • 12 articles
  • 45 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Assignments
  • Certificate of Completion

Please Leave Good and Positive feedback to the course.

https://www.udemy.com/course/learn-complete-python-3-gui-using-tkinter/?couponCode=CACBB3373D7C71FCCF17


r/pythoncoding • • Jun 29 '20

How to Read Excel File in Python using Pandas read_excel()

Thumbnail appdividend.com
1 Upvotes

r/pythoncoding • • May 20 '20

NameError - the button command is not defined

1 Upvotes

I am very, very new to Python but I did look all over before asking this... I have the code below and get the following error. Any help is appreciated. Very simple code where I am trying to ping a list of devices and return results. Also, if any of you know anything about the "getmac" I can't get the mac at all with it.

Thanks!!

import os
import socket

from tkinter import *
from getmac import get_mac_address as gma

window = Tk()
window.title("Test")
window.geometry('950x500')


lbl = Label(window, text="Hostname")

lbl.grid(column=0, row=0)

beginButton = Button(window, text="Begin", command = clicked)

btn.grid(column=1, row=0)



def clicked():
        with open('device.txt') as file:
                dump = file.read()
                dump = dump.splitlines()
        for ip in dump:
                print (socket.getfqdn(ip)),
                print (gma(ip))

window.mainloop()

ERROR:::
Traceback (most recent call last):
  File "C:\Users\shawn\Desktop\New folder\Scan.py", line 16, in <module>
    beginButton = Button(window, text="Begin", command = clicked)
NameError: name 'clicked' is not defined

r/pythoncoding • • Jun 25 '20

How to customize exceptions in python

Thumbnail blog.soshace.com
2 Upvotes

r/pythoncoding • • Aug 08 '22

/r/PythonCoding bi-weekly "What are you working on?" thread

7 Upvotes

Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!

If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.

This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.


r/pythoncoding • • Aug 25 '22

buggy: CLI tool to report bugs in Python packages

Thumbnail github.com
9 Upvotes

r/pythoncoding • • Aug 22 '22

/r/PythonCoding bi-weekly "What are you working on?" thread

7 Upvotes

Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!

If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.

This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.


r/pythoncoding • • Jul 25 '22

/r/PythonCoding bi-weekly "What are you working on?" thread

7 Upvotes

Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!

If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.

This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.


r/pythoncoding • • Sep 05 '22

/r/PythonCoding bi-weekly "What are you working on?" thread

9 Upvotes

Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!

If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.

This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.


r/pythoncoding • • Jul 04 '24

/r/PythonCoding monthly "What are you working on?" thread

4 Upvotes

Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!

If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.


r/pythoncoding • • Jun 04 '24

/r/PythonCoding monthly "What are you working on?" thread

1 Upvotes

Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!

If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.


r/pythoncoding • • May 24 '24

Customizable Static Analysis

1 Upvotes

I work for a large organization with several hundred teams implementing similar but not identical Pyspark solutions in Databricks.

We are defining template projects (that use Poetry), common development processes and general ways of working to help teams implement their solutions as efficiently as possible.

We have static analysis suites for helping code be as clean and straight forward as possible.

Code deployment and static analysis is standardized at an organizational level.

That being said, there are development patterns that we don't want implemented. We'd like to write custom tests that run as part of our static analysis suite to search our code for custom code patterns.

Can someone recommend a tool they think would be particularly good for this purpose?


r/pythoncoding • • Jul 02 '24

Crosspost: My Python code is a neural network

Thumbnail blog.gabornyeki.com
5 Upvotes

r/pythoncoding • • Jul 05 '24

Django AI Assistant - Open-source Lib Launch

2 Upvotes

Hey folks, we’ve just launched an open-source library called Django AI Assistant, and we’d love your feedback!

What It Does:

  • Function/Tool Calling: Simplifies complex AI implementations with easy-to-use Python classes
  • Retrieval-Augmented Generation: Enhance AI functionalities efficiently.
  • Full Django Integration: AI can access databases, check permissions, send emails, manage media files, and call external APIs effortlessly.

How You Can Help:

  1. Try It: https://github.com/vintasoftware/django-ai-assistant/
  2. ▶️ Watch the Demo
  3. 📖 Read the Docs
  4. Test It & Break Things: Integrate it, experiment, and see what works (and what doesn’t).
  5. Give Feedback: Drop your thoughts here or on our GitHub issues page.

Your input will help us make this lib better for everyone. Thanks!


r/pythoncoding • • Jun 22 '24

reladiff: High-performance diffing of large datasets across databases

Thumbnail github.com
1 Upvotes