Sign in to follow this  
Followers 0
tom13

How to let "if ... then" be order undependent?

8 posts in this topic

#1 ·  Posted (edited)

Hi,

I'm working on a poker bot. The bot reads a decision for each combination of cards from Strategy.ini - looks like this:

If $Card7 <> "" AND $Card6 <> "" AND $Card5 <> "" AND $Card4 <> "" AND $Card3 <> "" AND $Card2 <> "" AND $Card1 <> "" Then
$Decision = IniRead ( $StrategyFile, "7Cards", $Card1 & "|" & $Card2 & "|" & $Card3 & "|" & $Card4 & "|" & $Card5 & "|" & $Card6 & "|" & $Card7, "unknown" )
DecisionGo()
EndIf

This example is for when there are 7 cards (2 in your hand and 5 on the table).

The problem is that the order of the cards does not matters for my decision.

It can be

$card1|$card2|$card3|$card4|$card5|$card6|$card7

But it must make the same decision when the same cards are there but in an other order, for example:

$card4|$card2|$card1|$card7|$card6|$card5|$card3

Assuming that the cards are still the same of course.

Anyone can explain me how to do this with If ... then ?

Creating a new if ... then when $decision is unknown with a different order would be (almost) impossible, since there are 7 x 7 = 49 possibilities.

Edited by tom13

Share this post


Link to post
Share on other sites



Or well if some pro can tell me if this is not possible that would be nice..

Maybe I shouldn't use if ... then ? Any suggestions?

Share this post


Link to post
Share on other sites

Easiest way, I think, would be to sort the cards so that they are always in the same order for the decision. Something like:

#include <Array.au3>
Const $iAscending = 0
$CardTest = $Card1 & "|" & $Card2 & "|" & $Card3 & "|" & $Card4 & "|" & $Card5 & "|" & $Card6 & "|" & $Card7
$aCardTest = StringSplit($CardTest, "|")
$aSorted = _ArraySort($aCardTest, $iAscending, 1)
$CardTest = $aSorted[1] & "|" & $aSorted[2] & "|" & $aSorted[3] & "|" & $aSorted[4] _
    & "|" & $aSorted[5] & "|" & $aSorted[6] & "|" & $aSorted[7]
If Not StringInStr("|" & $CardTest & "|", "||") Then
    $Decision = IniRead ( $StrategyFile, "7Cards", $CardTest, "unknown" )
    DecisionGo()
EndIf

Hope this helps.


BlueBearrOddly enough, this is what I do for fun.

Share this post


Link to post
Share on other sites

Easiest way, I think, would be to sort the cards so that they are always in the same order for the decision. Something like:

#include <Array.au3>
Const $iAscending = 0
$CardTest = $Card1 & "|" & $Card2 & "|" & $Card3 & "|" & $Card4 & "|" & $Card5 & "|" & $Card6 & "|" & $Card7
$aCardTest = StringSplit($CardTest, "|")
$aSorted = _ArraySort($aCardTest, $iAscending, 1)
$CardTest = $aSorted[1] & "|" & $aSorted[2] & "|" & $aSorted[3] & "|" & $aSorted[4] _
    & "|" & $aSorted[5] & "|" & $aSorted[6] & "|" & $aSorted[7]
If Not StringInStr("|" & $CardTest & "|", "||") Then
    $Decision = IniRead ( $StrategyFile, "7Cards", $CardTest, "unknown" )
    DecisionGo()
EndIf

Hope this helps.

Hmmm, nice idea.. So I have to do the same when writing a new combination to Strategy.ini?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I tried it but getting an error.

Test Script:

#include <Array.au3>
$Card1 = "4d"
$Card2 = "Qc"
$Card3 = "Td"
$Card4 = "2h"
$Card5 = "Ah"
$Card6 = "9d"
$Card7 = "2d"

Const $iAscending = 0
$CardTest = $Card1 & "|" & $Card2 & "|" & $Card3 & "|" & $Card4 & "|" & $Card5 & "|" & $Card6 & "|" & $Card7
$aCardTest = StringSplit($CardTest, "|")
$aSorted = _ArraySort($aCardTest, $iAscending, 1)
$CardTest = $aSorted[1] & "|" & $aSorted[2] & "|" & $aSorted[3] & "|" & $aSorted[4] & "|" & $aSorted[5] & "|" & $aSorted[6] & "|" & $aSorted[7]
If Not StringInStr("|" & $CardTest & "|", "||") Then
    $Decision = IniRead ( $StrategyFile, "7Cards", $CardTest, "unknown" )
    MsgBox(4096, "Test", $CardTest)
EndIf

Error Code:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\Tom\Bureaublad\testa.au3"  
C:\Documents and Settings\Tom\Bureaublad\testa.au3 (14) : ==> Subscript used with non-Array variable.: 
$CardTest = $aSorted[1] & "|" & $aSorted[2] & "|" & $aSorted[3] & "|" & $aSorted[4] & "|" & $aSorted[5] & "|" & $aSorted[6] & "|" & $aSorted[7] 
$CardTest = $aSorted^ ERROR
>Exit code: 0   Time: 0.208

Unfortunately I have no idea what's wrong.. anyone does?

Edited by tom13

Share this post


Link to post
Share on other sites

I tried it but getting an error.

Test Script:

#include <Array.au3>
$Card1 = "4d"
$Card2 = "Qc"
$Card3 = "Td"
$Card4 = "2h"
$Card5 = "Ah"
$Card6 = "9d"
$Card7 = "2d"

Const $iAscending = 0
$CardTest = $Card1 & "|" & $Card2 & "|" & $Card3 & "|" & $Card4 & "|" & $Card5 & "|" & $Card6 & "|" & $Card7
$aCardTest = StringSplit($CardTest, "|")
$aSorted = _ArraySort($aCardTest, $iAscending, 1)
$CardTest = $aSorted[1] & "|" & $aSorted[2] & "|" & $aSorted[3] & "|" & $aSorted[4] & "|" & $aSorted[5] & "|" & $aSorted[6] & "|" & $aSorted[7]
If Not StringInStr("|" & $CardTest & "|", "||") Then
    $Decision = IniRead ( $StrategyFile, "7Cards", $CardTest, "unknown" )
    MsgBox(4096, "Test", $CardTest)
EndIf

Error Code:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\Tom\Bureaublad\testa.au3"  
C:\Documents and Settings\Tom\Bureaublad\testa.au3 (14) : ==> Subscript used with non-Array variable.: 
$CardTest = $aSorted[1] & "|" & $aSorted[2] & "|" & $aSorted[3] & "|" & $aSorted[4] & "|" & $aSorted[5] & "|" & $aSorted[6] & "|" & $aSorted[7] 
$CardTest = $aSorted^ ERROR
>Exit code: 0   Time: 0.208

Unfortunately I have no idea what's wrong.. anyone does?

Sure, _Arraysort() doesn't return the sorted array but is using ByRef to store it back into $aCardTest ....$aSorted contains the returncode for the function.

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Sure, _Arraysort() doesn't return the sorted array but is using ByRef to store it back into $aCardTest ....$aSorted contains the returncode for the function.

Ah, that explains alot.

Thanks alot JdeB :whistle:

Share this post


Link to post
Share on other sites

Sure, _Arraysort() doesn't return the sorted array

Oopsie. Sorry about that. :">

BlueBearrOddly enough, this is what I do for fun.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0