Source Code Cross Referenced for IfIsOccupied.java in  » Development » jgap » examples » gp » tictactoe » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » jgap » examples.gp.tictactoe 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /*
02:         * This file is part of JGAP.
03:         *
04:         * JGAP offers a dual license model containing the LGPL as well as the MPL.
05:         *
06:         * For licencing information please see the file license.txt included with JGAP
07:         * or have a look at the top of class org.jgap.Chromosome which representatively
08:         * includes the JGAP license policy applicable for any file delivered with JGAP.
09:         */
10:        package examples.gp.tictactoe;
11:
12:        import org.jgap.*;
13:        import org.jgap.gp.*;
14:        import org.jgap.gp.impl.*;
15:
16:        /**
17:         * The if-then construct. If-Condition is: if board free at position (X,Y),
18:         * then execute Z else do nothing.
19:         *
20:         * @author Klaus Meffert
21:         * @since 3.2
22:         */
23:        public class IfIsOccupied extends CommandGene {
24:            /** String containing the CVS revision. Read out via reflection!*/
25:            private final static String CVS_REVISION = "$Revision: 1.1 $";
26:
27:            private Class m_type;
28:
29:            private Board m_board;
30:
31:            public IfIsOccupied(final GPConfiguration a_conf, Board a_board,
32:                    Class a_type) throws InvalidConfigurationException {
33:                this (a_conf, a_board, a_type, 0, null);
34:            }
35:
36:            public IfIsOccupied(final GPConfiguration a_conf, Board a_board,
37:                    Class a_type, int a_subReturnType, int[] a_subChildTypes)
38:                    throws InvalidConfigurationException {
39:                super (a_conf, 3, CommandGene.VoidClass, a_subReturnType,
40:                        a_subChildTypes);
41:                m_type = a_type;
42:                m_board = a_board;
43:            }
44:
45:            public String toString() {
46:                return "if occupied(&1, &2) then (&3)";
47:            }
48:
49:            /**
50:             * @return textual name of this command
51:             *
52:             * @author Klaus Meffert
53:             * @since 3.2
54:             */
55:            public String getName() {
56:                return "If Occupied";
57:            }
58:
59:            public void execute_void(ProgramChromosome c, int n, Object[] args) {
60:                check(c);
61:                boolean condition;
62:                if (m_type == CommandGene.IntegerClass) {
63:                    int x = c.execute_int(n, 0, args);
64:                    if (x < 0 || x >= Board.WIDTH) {
65:                        throw new IllegalStateException("x must be 0.."
66:                                + Board.WIDTH);
67:                    }
68:                    int y = c.execute_int(n, 1, args);
69:                    if (y < 0 || x >= Board.HEIGHT) {
70:                        throw new IllegalStateException("y must be 0.."
71:                                + Board.HEIGHT);
72:                    }
73:                    condition = m_board.readField(x, y) != 0;
74:                } else {
75:                    throw new IllegalStateException(
76:                            "IfOccupied: cannot process type " + m_type);
77:                }
78:                if (condition) {
79:                    c.execute_void(n, 2, args);
80:                }
81:            }
82:
83:            /**
84:             * Determines which type a specific child of this command has.
85:             *
86:             * @param a_ind ignored here
87:             * @param a_chromNum index of child
88:             * @return type of the a_chromNum'th child
89:             *
90:             * @author Klaus Meffert
91:             * @since 3.2
92:             */
93:            public Class getChildType(IGPProgram a_ind, int a_chromNum) {
94:                if (a_chromNum == 0 || a_chromNum == 1) {
95:                    return m_type;
96:                }
97:                return CommandGene.VoidClass;
98:            }
99:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.