<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Tutorial &#8211; Evolving Neural Networks with SharpNEAT 2 (Part 1)</title>
	<atom:link href="http://www.nashcoding.com/2010/07/17/tutorial-evolving-neural-networks-with-sharpneat-2-part-1/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nashcoding.com/2010/07/17/tutorial-evolving-neural-networks-with-sharpneat-2-part-1/</link>
	<description>Yet Another Artificial Intelligence Blog</description>
	<lastBuildDate>Sat, 11 Feb 2012 21:19:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Spartacus</title>
		<link>http://www.nashcoding.com/2010/07/17/tutorial-evolving-neural-networks-with-sharpneat-2-part-1/comment-page-1/#comment-174</link>
		<dc:creator>Spartacus</dc:creator>
		<pubDate>Wed, 17 Nov 2010 22:26:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.nashcoding.com/?p=90#comment-174</guid>
		<description>Thank you very much for this.  The more documentation ....the better.</description>
		<content:encoded><![CDATA[<p>Thank you very much for this.  The more documentation &#8230;.the better.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roman T.</title>
		<link>http://www.nashcoding.com/2010/07/17/tutorial-evolving-neural-networks-with-sharpneat-2-part-1/comment-page-1/#comment-162</link>
		<dc:creator>Roman T.</dc:creator>
		<pubDate>Wed, 03 Nov 2010 19:07:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.nashcoding.com/?p=90#comment-162</guid>
		<description>Hi 
interesting tut i haven&#039;t read all yet, but i made some improvements on the OptimalPlayer, cause i won the first game against it. Now you can&#039;t win just stop the other from winning.


Here the knew code:

/* ***************************************************************************
 * This file is part of the NashCoding tutorial on SharpNEAT 2.
 * 
 * Copyright 2010, Wesley Tansey (wes@nashcoding.com)
 * 
 * Both SharpNEAT and this tutorial are free software: you can redistribute
 * it and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 *
 * SharpNEAT is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SharpNEAT.  If not, see .
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TicTacToeLib
{
    /// 
    /// A perfect Tic-Tac-Toe player.
    /// 
    public class OptimalPlayer : IPlayer
    {
        public SquareTypes SquareType { get; set; }

        public OptimalPlayer(SquareTypes type)
        {
            SquareType = type;
        }

        public Move GetMove(SquareTypes[,] board)
        {
            TicTacToeGame.GetWinner(board);

            int x = 0;
            int y = 0;

            //make a winning move if possible
            for (int i = 0; i &lt; 3; i++)
                for (int j = 0; j &lt; 3; j++)
                {
                    if (board[i, j] != SquareTypes.N)
                        continue;

                    board[i, j] = SquareType;
                    var winner = TicTacToeGame.GetWinner(board);
                    board[i, j] = SquareTypes.N;
                    if (winner == SquareType)
                        return new Move(i, j);
                }

            //if we can&#039;t win, check if there are any moves that we have to make
            //to prevent ourselves from losing
            for (int i = 0; i &lt; 3; i++)
                for (int j = 0; j &lt; 3; j++)
                {
                    if (board[i, j] != SquareTypes.N)
                        continue;

                    //set the move to the opponent&#039;s type
                    board[i, j] = SquareType == SquareTypes.X ? SquareTypes.O : SquareTypes.X;
                    var winner = TicTacToeGame.GetWinner(board);
                    board[i, j] = SquareTypes.N;

                    //if the opponent will win by moving here, move here to block them
                    if (winner != SquareTypes.N)
                        return new Move(i, j);
                }

            if (board[1, 1] == SquareTypes.N)
                return new Move(1, 1);


            if (SquareType == SquareTypes.O)
            {
                if (board[1, 1] == SquareTypes.X)
                {
                    for (int i = 0; i &lt; 3; i++)
                        for (int j = 0; j &lt; 3; j++)
                        {
                            switch (i)
                            {
                                case 0:
                                    x = 2;
                                    break;
                                case 1:
                                    x = 1;
                                    break;
                                case 2:
                                    x = 0;
                                    break;
                            }
                            switch (j)
                            {
                                case 0:
                                    y = 2;
                                    break;
                                case 1:
                                    y = 1;
                                    break;
                                case 2:
                                    y = 0;
                                    break;
                            }
                            if (board[i, j] == SquareTypes.X &amp;&amp; board[x, y] == SquareTypes.O)
                            {
                                return new Move(x, j);
                            }
                        }
                }
            }
            if (SquareType == SquareTypes.X)
            {
                if (board[1, 1] == SquareTypes.O)
                {
                    for (int i = 0; i &lt; 3; i++)
                        for (int j = 0; j &lt; 3; j++)
                        {
                            switch (i)
                            {
                                case 0:
                                    x = 2;
                                    break;
                                case 1:
                                    x = 1;
                                    break;
                                case 2:
                                    x = 0;
                                    break;
                            }
                            switch (j)
                            {
                                case 0:
                                    y = 2;
                                    break;
                                case 1:
                                    y = 1;
                                    break;
                                case 2:
                                    y = 0;
                                    break;
                            }
                            if (board[i, j] == SquareTypes.X &amp;&amp; board[x, y] == SquareTypes.O)
                            {
                                return new Move(x, j);
                            }
                        }
                }
            }


            //if we&#039;re here, that means we have made at least 1 move already and can&#039;t win
            //nor lose in 1 move, so just make the optimal play which would be to a free
            //corner that isn&#039;t blocked
            Move move = null;
            int max = -1;
            for (int i = 0; i &lt; 3; i++)
                for (int j = 0; j &lt; 3; j++)
                {
                    if (board[i, j] != SquareTypes.N)
                        continue;

                    board[i, j] = SquareType;
                    int count = 0;
                    for (int m = 0; m &lt; 3; m++)
                        for (int n = 0; n  max)
                    {
                        move = new Move(i, j);
                        max = count;
                    }
                }

            return move;
        }
    }
}

withe best Regards 

Roman T.</description>
		<content:encoded><![CDATA[<p>Hi<br />
interesting tut i haven&#8217;t read all yet, but i made some improvements on the OptimalPlayer, cause i won the first game against it. Now you can&#8217;t win just stop the other from winning.</p>
<p>Here the knew code:</p>
<p>/* ***************************************************************************<br />
 * This file is part of the NashCoding tutorial on SharpNEAT 2.<br />
 *<br />
 * Copyright 2010, Wesley Tansey (wes@nashcoding.com)<br />
 *<br />
 * Both SharpNEAT and this tutorial are free software: you can redistribute<br />
 * it and/or modify it under the terms of the GNU General Public License<br />
 * as published by the Free Software Foundation, either version 3 of the<br />
 * License, or (at your option) any later version.<br />
 *<br />
 * SharpNEAT is distributed in the hope that it will be useful,<br />
 * but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br />
 * GNU General Public License for more details.<br />
 *<br />
 * You should have received a copy of the GNU General Public License<br />
 * along with SharpNEAT.  If not, see .<br />
 */<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;</p>
<p>namespace TicTacToeLib<br />
{<br />
    ///<br />
    /// A perfect Tic-Tac-Toe player.<br />
    ///<br />
    public class OptimalPlayer : IPlayer<br />
    {<br />
        public SquareTypes SquareType { get; set; }</p>
<p>        public OptimalPlayer(SquareTypes type)<br />
        {<br />
            SquareType = type;<br />
        }</p>
<p>        public Move GetMove(SquareTypes[,] board)<br />
        {<br />
            TicTacToeGame.GetWinner(board);</p>
<p>            int x = 0;<br />
            int y = 0;</p>
<p>            //make a winning move if possible<br />
            for (int i = 0; i &lt; 3; i++)<br />
                for (int j = 0; j &lt; 3; j++)<br />
                {<br />
                    if (board[i, j] != SquareTypes.N)<br />
                        continue;</p>
<p>                    board[i, j] = SquareType;<br />
                    var winner = TicTacToeGame.GetWinner(board);<br />
                    board[i, j] = SquareTypes.N;<br />
                    if (winner == SquareType)<br />
                        return new Move(i, j);<br />
                }</p>
<p>            //if we can&#039;t win, check if there are any moves that we have to make<br />
            //to prevent ourselves from losing<br />
            for (int i = 0; i &lt; 3; i++)<br />
                for (int j = 0; j &lt; 3; j++)<br />
                {<br />
                    if (board[i, j] != SquareTypes.N)<br />
                        continue;</p>
<p>                    //set the move to the opponent&#039;s type<br />
                    board[i, j] = SquareType == SquareTypes.X ? SquareTypes.O : SquareTypes.X;<br />
                    var winner = TicTacToeGame.GetWinner(board);<br />
                    board[i, j] = SquareTypes.N;</p>
<p>                    //if the opponent will win by moving here, move here to block them<br />
                    if (winner != SquareTypes.N)<br />
                        return new Move(i, j);<br />
                }</p>
<p>            if (board[1, 1] == SquareTypes.N)<br />
                return new Move(1, 1);</p>
<p>            if (SquareType == SquareTypes.O)<br />
            {<br />
                if (board[1, 1] == SquareTypes.X)<br />
                {<br />
                    for (int i = 0; i &lt; 3; i++)<br />
                        for (int j = 0; j &lt; 3; j++)<br />
                        {<br />
                            switch (i)<br />
                            {<br />
                                case 0:<br />
                                    x = 2;<br />
                                    break;<br />
                                case 1:<br />
                                    x = 1;<br />
                                    break;<br />
                                case 2:<br />
                                    x = 0;<br />
                                    break;<br />
                            }<br />
                            switch (j)<br />
                            {<br />
                                case 0:<br />
                                    y = 2;<br />
                                    break;<br />
                                case 1:<br />
                                    y = 1;<br />
                                    break;<br />
                                case 2:<br />
                                    y = 0;<br />
                                    break;<br />
                            }<br />
                            if (board[i, j] == SquareTypes.X &amp;&amp; board[x, y] == SquareTypes.O)<br />
                            {<br />
                                return new Move(x, j);<br />
                            }<br />
                        }<br />
                }<br />
            }<br />
            if (SquareType == SquareTypes.X)<br />
            {<br />
                if (board[1, 1] == SquareTypes.O)<br />
                {<br />
                    for (int i = 0; i &lt; 3; i++)<br />
                        for (int j = 0; j &lt; 3; j++)<br />
                        {<br />
                            switch (i)<br />
                            {<br />
                                case 0:<br />
                                    x = 2;<br />
                                    break;<br />
                                case 1:<br />
                                    x = 1;<br />
                                    break;<br />
                                case 2:<br />
                                    x = 0;<br />
                                    break;<br />
                            }<br />
                            switch (j)<br />
                            {<br />
                                case 0:<br />
                                    y = 2;<br />
                                    break;<br />
                                case 1:<br />
                                    y = 1;<br />
                                    break;<br />
                                case 2:<br />
                                    y = 0;<br />
                                    break;<br />
                            }<br />
                            if (board[i, j] == SquareTypes.X &amp;&amp; board[x, y] == SquareTypes.O)<br />
                            {<br />
                                return new Move(x, j);<br />
                            }<br />
                        }<br />
                }<br />
            }</p>
<p>            //if we&#039;re here, that means we have made at least 1 move already and can&#039;t win<br />
            //nor lose in 1 move, so just make the optimal play which would be to a free<br />
            //corner that isn&#039;t blocked<br />
            Move move = null;<br />
            int max = -1;<br />
            for (int i = 0; i &lt; 3; i++)<br />
                for (int j = 0; j &lt; 3; j++)<br />
                {<br />
                    if (board[i, j] != SquareTypes.N)<br />
                        continue;</p>
<p>                    board[i, j] = SquareType;<br />
                    int count = 0;<br />
                    for (int m = 0; m &lt; 3; m++)<br />
                        for (int n = 0; n  max)<br />
                    {<br />
                        move = new Move(i, j);<br />
                        max = count;<br />
                    }<br />
                }</p>
<p>            return move;<br />
        }<br />
    }<br />
}</p>
<p>withe best Regards </p>
<p>Roman T.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris S</title>
		<link>http://www.nashcoding.com/2010/07/17/tutorial-evolving-neural-networks-with-sharpneat-2-part-1/comment-page-1/#comment-60</link>
		<dc:creator>Chris S</dc:creator>
		<pubDate>Fri, 23 Jul 2010 19:21:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.nashcoding.com/?p=90#comment-60</guid>
		<description>Great Read!
Thanks for the example/sample of TicTacToe with SharpNeat!</description>
		<content:encoded><![CDATA[<p>Great Read!<br />
Thanks for the example/sample of TicTacToe with SharpNeat!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

