Raised This Month: $32 Target: $400
 8% 

Comparing 3D Array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Drak
Veteran Member
Join Date: Jul 2005
Old 09-26-2010 , 10:03   Comparing 3D Array
Reply With Quote #1

I'm sure this is alot simpler then how I'm thinking of it. But I have:
Code:
new const g_Symbols[][1] = {     'A',     'B',     'C',     'D',     'E' } new g_UserSymbols[3][33][1] Foo() {     copy(g_UserSymbols[0][id],1,g_Symbols[random(sizeof(g_Symbols)]);     copy(g_UserSymbols[1][id],1,g_Symbols[random(sizeof(g_Symbols)]);     copy(g_UserSymbols[2][id],1,g_Symbols[random(sizeof(g_Symbols)]); }

And I want to know if "g_UserSymbols" contains 2/3 of the same letters.
IE:

Code:
g_UserSymbols[0] = A
g_UserSymbols[1] = B
g_UserSymbols[2] = A
I want to know that it contains two A's or B's or C's etc.
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-26-2010 , 15:36   Re: Comparing 3D Array
Reply With Quote #2

First, g_UserSymbols third dimension should be 2.
Otherwise a string won't fit.

Also, since you're assigning random values, this tut may help you:
https://forums.alliedmods.net/showthread.php?t=74666
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-26-2010 , 23:30   Re: Comparing 3D Array
Reply With Quote #3

If you are only working with only a single character then you can eliminate the third dimension all together. If you want, explain what you are attempting to do and we can maybe recommend a better way.

Try this:
PHP Code:
#include <amxmodx>

new const g_Symbols[] =
{
    
'A',
    
'B',
    
'C',
    
'D',
    
'E'
};
new 
g_UserSymbols][ 33 ];

public 
plugin_init() 
{
    
register_concmd"test" "Foo" );
}

public 
Fooid )
{
    
g_UserSymbols][ id ] = g_Symbolsrandomsizeofg_Symbols ) ) ];
    
g_UserSymbols][ id ] = g_Symbolsrandomsizeofg_Symbols ) ) ];
    
g_UserSymbols][ id ] = g_Symbolsrandomsizeofg_Symbols ) ) ];

    
server_print"Symbols=%c%c%c - Double? %d" g_UserSymbols][ id ] , g_UserSymbols][ id ] , g_UserSymbols][ id ] , CheckDoubleid ) );
}

public 
bool:CheckDoubleid )
{    
    new 
iChecked;
    
    for ( new 
sizeofg_UserSymbols ) ; i++ )
    {
        if ( 
iChecked & ( << ( g_UserSymbols][ id ] - 'A' ) ) )
            return 
true;
        
        
iChecked |= ( << ( g_UserSymbols][ id ] - 'A' ) );
    }
    
    return 
false;

__________________

Last edited by Bugsy; 09-26-2010 at 23:59.
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-26-2010 , 23:51   Re: Comparing 3D Array
Reply With Quote #4

@Bugsy
That doesn't work as a string anymore then.
Symbols=%s%s%s

Symbols=%c%c%c
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-26-2010 , 23:59   Re: Comparing 3D Array
Reply With Quote #5

Quote:
Originally Posted by Exolent[jNr] View Post
@Bugsy
That doesn't work as a string anymore then.
Symbols=%s%s%s

Symbols=%c%c%c
True, though they will print the same. I'll change to %c for the sake of correctness
__________________

Last edited by Bugsy; 09-27-2010 at 00:01.
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:36.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode