Skip to content
Fix Code Error

Getting the index of the returned max or min item using max()/min() on a list

March 13, 2021 by Code Error
Posted By: Anonymous

I’m using Python’s max and min functions on lists for a minimax algorithm, and I need the index of the value returned by max() or min(). In other words, I need to know which move produced the max (at a first player’s turn) or min (second player) value.

for i in range(9):
    new_board = current_board.new_board_with_move([i / 3, i % 3], player)

    if new_board:
        temp = min_max(new_board, depth + 1, not is_min_level)  
        values.append(temp)

if is_min_level:
    return min(values)
else:
    return max(values)

I need to be able to return the actual index of the min or max value, not just the value.

Solution

if is_min_level:
    return values.index(min(values))
else:
    return values.index(max(values))
Answered By: Anonymous

Related Articles

  • Combining items using XSLT Transform
  • How do I keep only the first map and when the game…
  • Casting &i32 as usize
  • error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or…
  • Can't install via pip because of egg_info error
  • Binance WebSocket Order Book - depths change every time
  • Peak signal detection in realtime timeseries data
  • Java - Regex, nested recursion match
  • How do I include certain conditions in SQL Count
  • Segmentation Core Dump Problem in Dijkstra Algorithm
  • Java Minecraft Plugin EventHandler?
  • How to hide/disable buttons controls in videojs?
  • Does the code after the recursion call get executed…
  • What's the difference between eval, exec, and compile?
  • Convert array to nested JSON object - Angular Material tree
  • What is the optimal algorithm for the game 2048?
  • Rust lifetime confusion
  • JavaScript - How to have collision with character…
  • How to add 'load more' functionality to items on a…
  • Getting infinite loop after entering 2 objects to…
  • Active tab issue on page load HTML
  • How to move the player across a one background image?
  • Multiple dynamic segments in ember.js
  • Display Grid does not work in Polymer correctly
  • How to make vuetify navigation drawer to close group…
  • Improved way to get subsets of a list
  • Fastest way to list all primes below N
  • Import Python Script Into Another?
  • How to show title in hover - css / jquery
  • How do I merge two dictionaries in a single…
  • Calculate sum for group of dynamic table rows in jquery
  • Centering in CSS Grid
  • How to animate list items in Vue when one is removed
  • Extracting the top 5 maximum values in excel
  • binding backbone form view UIto model change to…
  • Ukkonen's suffix tree algorithm in plain English
  • creating a python 2 player game with functions & classes
  • Unity 2D - Jump Function Doesn't Work Properly
  • How to write integers alongside pixels in the…
  • Is gl_FragDepth equal gl_FragCoord.z when msaa enable?
  • HashSet vs. List performance
  • How to update Python?
  • Onclick, the button moves down, why can that due to?
  • When should I use a List vs a LinkedList
  • In this tic tac toe game, why the last move of last…
  • Styling active-class in Vuetify
  • How can I ensure a dataframe has completed being…
  • Install pip in docker
  • YouTube iframe API: how do I control an iframe…
  • Vuetify v-tabs v-tab-item overflows window width
  • How to store custom objects in NSUserDefaults
  • Getting the closest string match
  • What are type hints in Python 3.5?
  • How do I copy a range of formula values and paste…
  • How to change settings for a specific player in Photon?
  • How to avoid using Select in Excel VBA
  • Vuetify v-list-item style change on hover
  • Excel VBA For Each Worksheet Loop
  • Valid values for android:fontFamily and what they map to?
  • How to create range in Swift?
  • How to use java.net.URLConnection to fire and handle…
  • Dart core element core-collapse
  • How do I pass a unique_ptr argument to a constructor…
  • detect dynamically checkboxes/polymer elements…
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • changing code from fs to fs-extra using node js
  • How to specify line breaks in a multi-line flexbox layout?
  • Unexpected end of JSON input while parsing
  • Why is "1000000000000000 in range(1000000000000001)"…
  • Scraping Tables in Python Using Beautiful Soup…
  • Perfomance issues with large number of elements in…
  • A function in C that adds a node at the end of a…
  • Firebase deployng Sapper app as cloud function failed
  • How to loop back to start of question in case of…
  • What does the Excel range.Rows property really do?
  • in doesn't call method on item change
  • AppCompat v7 r21 returning error in values.xml?
  • V-Html with Updated doesn’t work
  • Collapse a vector of function calls in to one line,…
  • Excel VBA: AutoFill Multiple Cells with Formulas
  • How do I switch two players in tic-tac-toe game in Python?
  • Return from lambda forEach() in java
  • How do you rotate canvas element to mouse position,…
  • Bootstrap Card - change width
  • What is the copy-and-swap idiom?
  • Smart way to truncate long strings
  • Error: Expression must have integral or unscoped enum type
  • How to Correctly Use Lists in R?
  • Calling variable defined inside one function from…
  • How to create unique keys for React elements?
  • NameError: global name 'xrange' is not defined in Python 3
  • Haskell restricting a RoseTree to depth n
  • What does Ruby have that Python doesn't, and vice versa?
  • Is there a reason why it doesn't go to the 'else if'…
  • How to make different animations for keyboard input
  • SHA512 vs. Blowfish and Bcrypt
  • How to play a sound using Swift?
  • How to delete an item in a list if it exists?
  • How to change the range slider addition by click on…
  • How to solve race condition in Javascript?

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Convert Month Number to Month Name Function in SQL

Next Post:

How to downgrade from Internet Explorer 11 to Internet Explorer 10?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error