Python Forum
How to add an element such as an average to a multi-dimensional array?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add an element such as an average to a multi-dimensional array?
#1
I am working on my first project with machine learning and training AI with rewards an loses on a game of Tic Tac Toe. I have everything but this problem solved on paper. I can't figure out how I can add the AI's moves to an array and give them a reward.

The way I wanted to do this was use a huge array that stores all the information in a format of whether they started or their opponent started (1 or 2) then they move number (1, 2, 3, 4, and sometimes 5) and then add which square they chose and at the end either add 1 for a win or subtract 1 for a loss. This is how I thought I should format my code.
#1, 2, 3
#4, 5, 6
#7, 8, 9
oBoard = []
#Sets 1 for when they start and 2 for when opponent starts
for sTurnNum in range(2):
    oBoard.append([sTurnNum+1])
    for turnNum in range(5):
        #Sets an empty set for every possible turn 1-5
        oBoard[sTurnNum].append([turnNum+1])
When I print this I get
Output:
[[1, [1], [2], [3], [4], [5]], [2, [1], [2], [3], [4], [5]]]
and I can add what block they choose. If I simulate the game I get where the bot starts first:
Output:
[[1, [1, [5]], [2], [3], [4], [5]]] Bot chooses space 5, player chooses space 1 [[1, [1, [5]], [2, [5, [7]]], [3], [4], [5]]] Bot chooses space 7, player chooses space 8 [[1, [1, [5]], [2, [5, [7]]], [3, [5, [7, [3]]]], [4], [5]]] Bot gets 3 in a row, 3-5-7. Set of moves should get rewarded 1 so [[1, [1, [5, [total="1"]], [2, [5, [7, [total="1"]]]], [3, [5, [7, [3, [total="1"]]]]], [4], [5]]] Then be able to get that total to see if the bot should pick that space if it is a good total or not once it gets past its learning trail
Reply


Messages In This Thread
How to add an element such as an average to a multi-dimensional array? - by xhughesey - Jan-06-2019, 07:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  RandomForest --ValueError: setting an array element with a sequence JaneTan 0 1,761 Sep-08-2021, 02:12 AM
Last Post: JaneTan
  I am trying to change the value of an element in a record array ingu 1 2,203 Jan-14-2020, 01:30 PM
Last Post: perfringo
  TensorFlow get error - array with more than one element is ambiguous vokoyo 3 5,589 Nov-07-2019, 01:12 PM
Last Post: ThomasL
  How convert multidimensional array to two dimensional array tkkhan44 1 2,797 Feb-20-2019, 05:00 AM
Last Post: scidam
  Three-dimensional Contour Plots minifizikus 1 3,299 Sep-13-2018, 10:56 PM
Last Post: Larz60+
  Convert element of list to integer(Two dimentional array) zorro_phu 3 4,821 Jun-12-2018, 04:49 AM
Last Post: zorro_phu
  2 Dimensional NumPy for beginners Jack_Sparrow 2 3,134 May-08-2018, 05:21 PM
Last Post: killerrex
  Recurse through n-dimensional array ColdDeath 2 3,000 Apr-05-2018, 11:20 AM
Last Post: KenniT
  ValueError: The truth value of an array with more than one element is ambiguous. Eliza5 1 14,373 Apr-02-2018, 12:03 AM
Last Post: scidam
  Two Dimensional Chart from CSV File srini1995 0 2,254 Nov-27-2017, 07:10 AM
Last Post: srini1995

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020