Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members

Plasmocyte.cs

Go to the documentation of this file.
00001 /*
00002 SimImmuno version 1.0
00003 Copyright (C) 2005 sebeuh.ajsinfo.net
00004 
00005 SimImmuno est libre, vous pouvez le redistribuer et/ou le modifier
00006 selon les termes de la Licence Publique Générale GNU publiée par la
00007 Free Software Foundation (version 2).
00008 
00009 SimImmuno est distribué car potentiellement utile, mais SANS AUCUNE GARANTIE,
00010 ni explicite ni implicite, y compris les garanties de commercialisation
00011 ou d'adaptation dans un but spécifique. Reportez-vous à la
00012 Licence Publique Générale GNU pour plus de détails.
00013 
00014 Texte de la license officielle (anglais) :
00015 http://simimmuno.ajsinfo.net/text.aspx?code=no&txt_file=GPL.txt
00016 Traduction francaise (non-officielle) :
00017 http://simimmuno.ajsinfo.net/text.aspx?code=no&txt_file=GPL-fr.txt
00018 */
00019 using System;
00020 
00021 namespace SimImmuno
00022 {
00023         [Serializable]
00024         public class Plasmocyte : Cellule
00025         {
00026                 int active_by_il = 0;
00027 
00028                 public Plasmocyte(int x, int y,int spe) : base(x,y)
00029                 {
00030                         Life = 2000;
00031                         specificite = spe;
00032                         cell_plusproche = null;
00033                 }
00034 
00035                 public Plasmocyte(int x, int y,int spe, int life) : base(x,y)
00036                 {
00037                         Life = life;
00038                         specificite = spe;
00039                         cell_plusproche = null;
00040                 }
00041 
00042                 new public void Action()
00043                 {
00044                         if(active_by_il != 0)
00045                                 active_by_il--;
00046                         Mouvement();
00047                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00048                         int tmp = 0;
00049                         foreach(Cellule cell in ccol_copy)
00050                         {
00051                                 double dst = DistTo(cell,this);
00052                                 if(dst < 200 && tmp == 0)
00053                                 {
00054                                         if(cell is Antigen)
00055                                         {
00056                                                 if(specificite == cell.specificite)
00057                                                 {
00058                                                         int b = rnd.Next(1,10);
00059                                                         for(int a=0;a<b;a++)
00060                                                         {
00061                                                                 ProdAC(cell);
00062                                                         }
00063                                                         frmMain.log.NewEvent("Ag n°" + cell.index.ToString() + " detecté,prod. de " + b.ToString() + " AC Spé:" + specificite.ToString());
00064                                                         tmp++;
00065                                                 }
00066                                         }
00067                                         else if(cell is VIH)
00068                                         {
00069                                                 if(specificite == cell.specificite)
00070                                                 {
00071                                                         int b = rnd.Next(1,10);
00072                                                         for(int a=0;a<b;a++)
00073                                                         {
00074                                                                 ProdAC(cell);
00075                                                         }
00076                                                         frmMain.log.NewEvent("VIH n°" + cell.index.ToString() + " detecté,prod. de " + b.ToString() + " AC Spé:" + specificite.ToString());
00077                                                         tmp++;
00078                                                 }
00079                                         }
00080                                 }
00081                         }
00082                         return;
00083                 }
00084 
00085                 public void Activation(Cellule iLB)
00086                 {
00087                         if(active_by_il == 0)
00088                                 active_by_il = 200;
00089                         return;
00090                 }
00091 
00092                 private void ProdAC(Cellule icell)
00093                 {
00094                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00095                         int count = 0;
00096                         foreach(Cellule cell in ccol_copy)
00097                         {
00098                                 if(cell is Anticorp)
00099                                         if(cell.specificite == icell.specificite)
00100                                         {
00101                                                 count++;        
00102                                         }
00103                         }
00104                         if(count < 20)
00105                         {
00106                                 int x = rnd.Next(-5,5);
00107                                 int y = rnd.Next(-5,5);
00108                                 Anticorp ac1 = new Anticorp(icell.Location.X+x,icell.Location.Y+y,specificite);
00109                                 frmMain.ccol.Add(ac1);
00110                         }
00111                 }
00112 
00113                 private void Mouvement()
00114                 {
00115                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00116                         if(cell_plusproche != null)
00117                         {
00118                                 if((TestIfAlive(cell_plusproche)))
00119                                 {
00120                                         if(cell_plusproche.Location.X < this.Location.X)
00121                                                 this.Location.X = this.Location.X - 5;
00122                                         else
00123                                                 this.Location.X = this.Location.X + 5;
00124                                         if(cell_plusproche.Location.Y < this.Location.Y)
00125                                                 this.Location.Y = this.Location.Y - 5;
00126                                         else
00127                                                 this.Location.Y = this.Location.Y + 5;
00128                                 }
00129                                 else
00130                                         cell_plusproche = null;
00131                         }
00132                         else
00133                         {
00134                                 foreach(Cellule cell in ccol_copy)
00135                                 {
00136                                         int perimetre;
00137                                         if(active_by_il != 0)
00138                                                 perimetre = 45000;
00139                                         else
00140                                                 perimetre = 20000;
00141                                         if(DistTo(this,cell) < perimetre)
00142                                         {
00143                                                 if(cell is Antigen || cell is VIH)
00144                                                 {
00145                                                         if(cell.specificite == this.specificite)
00146                                                         {
00147                                                                 if(!(TestIfDejaSelect(cell)))
00148                                                                 {
00149                                                                         if(cell_plusproche == null)
00150                                                                                 cell_plusproche = cell;
00151                                                                         if(DistTo(this,cell_plusproche) > DistTo(this,cell))
00152                                                                                 cell_plusproche = cell;
00153                                                                 }
00154                                                         }
00155                                                 }
00156                                         }
00157                                 }
00158                                 int tmp2 = rnd.Next(2);
00159                                 int x,y;
00160                                 if(tmp2 == 0)
00161                                 {
00162                                         x = this.Location.X + rnd.Next(-5,5);
00163                                         y = this.Location.Y + rnd.Next(-5,5);
00164                                 }
00165                                 else
00166                                 {
00167                                         x = this.Location.X - rnd.Next(-5,5);
00168                                         y = this.Location.Y - rnd.Next(-5,5);
00169                                 }
00170                                 this.Location.X = x;
00171                                 this.Location.Y = y;
00172                         }
00173                 }
00174 
00175                 private bool TestIfAlive(Cellule cell)
00176                 {
00177                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00178                         bool tmp = false;
00179                         foreach(Cellule icell in ccol_copy)
00180                         {
00181                                 if(icell.index == cell.index && icell.specificite == cell.specificite  && tmp == false)
00182                                 {
00183                                         if(icell is Antigen || cell is VIH)
00184                                         {
00185                                                 double dst = DistTo(cell,icell);
00186                                                 if(dst < 200)
00187                                                         tmp = true;
00188                                         }
00189                                 }
00190                         }
00191                         return tmp;
00192                 }
00193 
00194                 private bool TestIfDejaSelect(Cellule cell)
00195                 {
00196                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00197                         bool tmp = false;
00198                         foreach(Cellule icell in ccol_copy)
00199                         {
00200                                 if(icell is Plasmocyte && tmp == false)
00201                                 {
00202                                         if(icell.cell_plusproche == cell)
00203                                                 tmp = true;
00204                                         else
00205                                                 tmp = false;
00206                                 }
00207                         }
00208                         return tmp;
00209                 }
00210         }
00211 }

Generated on Sat Jun 4 15:03:42 2005 for SimImmuno by  doxygen 1.4.2