baavgai's Profile User Rating: *****

Reputation: 5643 Overlord
Group:
Mentors
Active Posts:
12,360 (5.2 per day)
Joined:
16-October 07
Profile Views:
118,924
Last Active:
User is offline Today, 08:34 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Who Cares
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
725
Expert In:
C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

Latest Visitors

Icon   baavgai has not set their status

Posts I've Made

  1. In Topic: CandyMachine project, don't know where to start

    Posted 16 Apr 2014

    Crap, sorry, response not apropos to necro.
  2. In Topic: Cannot Query more than one data

    Posted 16 Apr 2014

    First, T-SQL is the procedural language for a database. Don't mistake it for a general purpose language, because it kind of sucks for that.

    If you want something akin to an array of objects in a database... it's called a table. ;)

    If you want to loop through that data, which is generally a bad idea, the construct that will help you is called a cursor.

    e.g.
    declare @foo table(id int identity(1,1), name nvarchar(100))
    insert into @foo(name) values ('Packet-Eye')
    insert into @foo(name) values ('Wiggy')
    insert into @foo(name) values ('Wimax-Lite')
    insert into @foo(name) values ('Wimax-Home') 
    
    -- select * from @foo
    
    declare @name nvarchar(100)
    declare c cursor for select name from @foo
    open c
    fetch next from c into @name 
    while (@@FETCH_STATUS=0) begin
    	print @name
    	fetch next from c into @name 
    end
    close c
    deallocate c
    
    


    If it looks kludgey, it kind of is.

    I'll often load a result set into a temp table and loop through it, removing rows as I go. e.g.
    while exists(select * from @foo) begin
    	declare @key int, @name nvarchar(100)
    	select @key=MIN(id) from @foo
    	select @name=name from @foo where id=@key
    	print @name
    	delete from @foo where id=@key
    end
    
    


    Again, sometimes you must loop through data in T-SQL. However, it's the least efficient way to process data and should be used as a last resort.
  3. In Topic: SQL Query by distance

    Posted 15 Apr 2014

    Yes. However, avoiding SQRT can be a significant optimization. Also, avoiding POW can be as well.
  4. In Topic: Simplyfy MiniMax Algorithm Tic Tac Toe

    Posted 15 Apr 2014

    For some reason, "not bestscore" didn't seem to be evaluating to true when it was None. Which doesn't make sense. I did a quick sanity check:
    >>> x = None
    >>> x
    >>> not x
    True
    >>> x == None
    True
    >>> 
    
    


    So, I'm still confused on that. Python prefers just variable or not variable for boolean evaluation when you can...

    Ah, I'm no longer confused:
    >>> x = 0
    >>> x
    0
    >>> if x:
    ...     print True
    ... else:
    ...     print False
    ... 
    False
    
    


    The int value 0 also evaluated to false. Since we were using integers, I got burned.

    The other was that when you toggle isMax in the min_max, you also need to toggle the marker. You'll see the first version has it statically set to self.marker, which is wrong. The one that works takes a marker value that it then toggles.

    The toggle is moderately redundant here, since the side can be derived from the isMax value, but that seemed like more work.
  5. In Topic: Simplyfy MiniMax Algorithm Tic Tac Toe

    Posted 15 Apr 2014

    Right, two bugs. One, None doesn't evaluate as boolean False ( thought it did. ) Two, the side changes with the min max.

    So:
    class AI:
        def __init__(self, marker):
            self.marker, self.opponentmarker = marker, self.toggle(marker)
            self.type = 'C'
    
        def move(self,gameinstance):
            move_position,score = self.min_max_move(gameinstance, True, self.marker)
            gameinstance.mark(self.marker,move_position)
    
        def toggle(self, marker):
            if marker == 'X':
                return 'O'
            return 'X'
    
        def min_max_move(self, gameinstance, isMax, marker):
            def cmp(score, bestscore):
                if bestscore == None:
                    return True
                if isMax:
                    return score > bestscore
                return score < bestscore
    
            bestscore, bestmove = None, None
            for m in gameinstance.get_free_positions():
                gameinstance.mark(marker,m)
    
                if gameinstance.is_gameover():
                    score = self.get_score(gameinstance)
                else:
                    move_position, score = self.min_max_move(gameinstance, not isMax, self.toggle(marker))
    
                gameinstance.revert_last_move()
                if cmp(score, bestscore):
                    bestscore, bestmove = score, m
            return bestmove, bestscore
    
    
        def get_score(self,gameinstance):
            if gameinstance.is_gameover():
                if gameinstance.winner  == self.marker:
                    return 1 # Won
                elif gameinstance.winner == self.opponentmarker:
                    return -1 # Opponent won
            return 0 # Draw
    
    


    I have numerous issues with the code this is based off of. In any case, that's as clean as I can get this.

My Information

Member Title:
Dreaming Coder
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Jersey, be afraid.
Years Programming:
25
Programming Languages:
Most.

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://

Comments

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  1. Photo

    8byte Icon

    10 Jan 2014 - 11:08
    Awesome, thanks for all the help!
  2. Photo

    codiddle Icon

    07 Mar 2013 - 18:59
    GENIUS GUY HERE MAN. Write a book!
  3. Photo

    mamelove25 Icon

    19 Feb 2013 - 10:53
    Hello My Dear, My Name is Mame. i saw your profile today and became interested in you,i will also like to know you more,and if you can send an email to my email address,i will give you my pictures here is my email address (mame25live@yahoo.co.uk) I believe we can move from here! Am waiting for your mail to my email address above because i have much to tell you,
    love Miss Mame.
  4. Photo

    bilbil0629 Icon

    24 Oct 2012 - 05:39
    hey! you mongolian?
  5. Photo

    Ticon Icon

    20 Aug 2012 - 13:23
    I just noticed your an expert in cheese. I lol'd
  6. Photo

    mostyfriedman Icon

    18 Aug 2012 - 23:13
    Hello there Brett
  7. Photo

    MehrdadSecret Icon

    26 Jul 2012 - 05:51
    hello, can i have a contact email or Yahoo or something? Need ur help badly
  8. Photo

    Jeet.in Icon

    18 Apr 2012 - 23:17
    Thanks ! Solved My problem !
    http://www.dreamincode.net/forums/topic/275578-simple-whitespace-remover/page__gopid__1603556&#entry1603556
  9. Photo

    RetardedGenius Icon

    25 Oct 2011 - 14:29
    I agree so much with your opinion of incompetent CS teachers. So true!
    http://www.dreamincode.net/forums/topic/252848-venting-a-frustration/page__view__findpost__p__1469659
  10. Photo

    WabiSabi Icon

    21 Oct 2011 - 11:00
    I agree with assert(C). However, I'd rather not specify what you are "the best" at.
  11. Photo

    assert(C) Icon

    20 Oct 2011 - 08:38
    You are the best
  12. Photo

    macosxnerd101 Icon

    30 Sep 2011 - 09:33
    Congrats on hitting the big 3k!
  13. Photo

    sjin Icon

    16 Aug 2011 - 18:41
    This guy is AWESOME! Cheers bro!
  14. Photo

    hulla Icon

    02 Aug 2011 - 02:50
    Wow that's alot of programming languages... :O
  15. Photo

    Aphex19 Icon

    04 Jul 2011 - 16:54
    Kudos to you baavgai, the most well deserved mentor on DIC in my opinion.
  • (3 Pages)
  • +
  • 1
  • 2
  • 3