winzip icon

ants

Email
Submitted on: 1/1/2015 3:07:00 PM
By: vsim (from psc cd)  
Level: Intermediate
User Rating: By 9 Users
Compatibility: C
Views: 1247
 
     There are two homes for the ants.Red and black ants come out from there and go to sugar .
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :ants
//**************************************
.model small
.stack 45000
.586
include bios.inc
include dos.inc
.data
four dw 4
eight dw 8
Hole_Black_X EQU 70
Hole_Black_Y EQU 5
Hole_Red_XEQU 40
Hole_Red_Y EQU 12
Sugar1_XEqu 60
Sugar1_YEqu 8
Sugar1_Knt Equ 100
Sugar2_XEqu 5
Sugar2_YEqu 22
Sugar2_Knt Equ 150
Sugar3_XEqu 55
Sugar3_YEqu 5
Sugar3_Knt Equ 50
Sugar4_XEqu 75
Sugar4_YEqu 22
Sugar4_Knt Equ 10
antsnumber dw 0
movement dw 0
count dw 0
mem1 dw 0
IsInit db 0
colorr db 0
colorb db 0
rholey db 0
rholex db 0
bholey db 0
bholex db 0
one equ 1
num db 0
sPfirstant word 0
 homecolum dw 0
 number dw 0
 fa dw 0
.code
SetPosition Proto near C Col:byte,Row:byte
ColorChar Proto near C Character:byte,Atrri:byte
InitFarm proto near c, farm:word
createant Proto near C ,antranch:word,color:byte,yhole:byte,xhole:byte
Addant Proto near C,spAnt:word
Bays_etal Proto near C
 PlzWait Proto near C time:word
 Show2 Proto near c,farm:word
 Display Proto near C
 ClrScrn Proto near C,x:byte,y:byte
walkant proto near c, spant:word, farm:word
;;findxyant Proto near C,word,byte,byte
;; deleteant Proto near C,word,word
;;nextant Proto near C,word
Show proc near C uses si di ,
 farm2:word
.if( IsInit == 0 )
 Invoke InitFarm, farm2
 mov IsInit, 1
 invoke Display
.endif
 ret
 show endp
 InitFarm proc near c uses si di,
 farm:word
 mov count,0
mov si,farm
 mov bx,0
 mov ax,0 ;row
 mov dx,0 ;colum
 mov cx, 80 * 25 ;inialize hole farm
 l1:
inc count
mov [si+bx],dl
inc dl
inc bx
mov [si+bx],al
inc bx
mov word ptr [si+bx], 0
add bx,14
cmp count,80
jae colum
l3:
loop l1
 jmp l2
	colum:
inc al
mov dl,0
	mov count,0
jmp l3
l2:
ret
InitFarm endp
 Display proc near C uses si di
 Invoke SetPosition,Hole_Black_X,Hole_Black_Y
 invoke ColorChar ,66,7
 Invoke SetPosition,Hole_Red_X,Hole_Red_Y
 invoke ColorChar,82,4
 Invoke SetPosition,Sugar1_X,Sugar1_Y
 invoke ColorChar,83,7
 Invoke SetPosition,Sugar2_X,Sugar2_Y
 Invoke ColorChar,83,7
Invoke SetPosition,Sugar3_X,Sugar3_Y
Invoke ColorChar,83,7
Invoke SetPosition,Sugar4_X,Sugar4_Y
invoke ColorChar,83,7
 ret
Display endp
OneStep proc near C uses si di ss ds bp,
 AntRanch:word
mov si,antranch
 mov colorr,0
 mov bholeX,70
 mov bholeY,5
 Invoke createant,AntRanch,colorb,bholeX,bholeY
;Invoke Show2,Antranch
 mov colorr,1
 mov rholeX,40
 mov rholeY,12
 Invoke createant,AntRanch,colorr,rholeX,rholeY
 mov ax,spFirstAnt ;;;;;;;;;;
 .while(ax!=0)
	mov es,ax
	mov ax, word ptr es:[12]
	 push ax
	 Invoke walkant,es,antranch
	 pop ax
	 .endw
 invoke Show2,antranch
 invoke display
 ret
 OneStep endp
;;;;;;This function get the random number of ants and also make;;
;;;;;;;Them walk;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 createant proc near C uses si di ss bp,
	 AntRanch:word,
 color:byte,
 xhole:byte,
 yhole:byte
	 ;finit
	 mov si,AntRanch
 Invoke Bays_etal ;get ant crate some
 mov bx,ax
 fld real8 ptr[bx]
	 fild four
	 fmul
 fistp antsnumber
	 .while(antsnumber > 0)
 Invoke AddAnt,spFirstAnt;add ant
 mov spFirstAnt,ax
 mov es,ax
;move pointer offirst ant to antlist
 mov dh,xhole
	 mov es:[0],dh	;put in x position
	 mov dh,yhole
	 mov byte ptr es:[1],dh ;put in y value of ant list
	 mov byte ptr es:[2], 0	;phermone
 mov bl,color
 mov es:[14], bl ;word
;;;;;;now get the random number and move the ants;;;;
mov bx,0
		mov ax,0
 movzx ax,xhole
 mov dx,16
 mul dx
 
 movzx ax,yhole
 mov dx,80
 mul dx
; mov di,ax
mov dx,16
mul dx
	mov bx,ax
		add bx,2
		 mov cx,di
	 add bx,cx
 add word ptr [si][bx],1 ;add one to home counter
	 dec antsnumber
	 .endw
 ret
 createant endp
walkant proc near c uses si di, spant:word, farm:word
 local xhole:byte, yhole:byte
	 mov si, farm
 mov ax, spant
 mov es, ax
 mov ax, es:[0]
 mov xhole, al
 mov yhole, ah
 movzx ax,xhole
 mov dx,16
 mul dx
 mov di,ax;;;;;;;;check the answer
 movzx ax,yhole
 mov dx,80
 mul dx
; mov di,ax
mov dx,16
mul dx
	mov bx,ax
		add bx,2
		 mov cx,di
	 add bx,cx
 sub word ptr [si][bx],1 ;add one to home counter
	 Invoke Bays_etal
 mov bx,ax
	 fld real8 ptr [bx]
	 fild eight
	 fmul
	 fistp movement
	 .if(movement==0)
	 dec byte ptr es:[1] ;decrement y position in link list
	 mov dl ,byte ptr es:[1]
 mov yhole,dl
 .endif
 .if(movement==1)
	inc byte ptr es:[0] ;increment x position in link list
	mov dl,byte ptr es:[0] ;change the xposition in home cell
mov xhole,dl
		dec byte ptr es:[1]	 ;change yposition in home cell
	mov dl,byte ptr es:[1]
mov yhole,dl
.endif
.if(movement==2)
	inc byte ptr es:[0]
	mov dl,byte ptr es:[0]
mov xhole,dl
.endif
.if(movement==3)
	inc byte ptr es:[0]
	mov dl,byte ptr es:[0]
mov xhole,dl
	inc byte ptr es:[1]
	mov dl,byte ptr es:[1]
mov yhole,dl
.endif
.if(movement==4)
	inc byte ptr es: [1]
	mov dl,byte ptr es:[1]
mov yhole,dl
.endif
.if(movement==5)
	dec byte ptr es:[0]
	mov dl,byte ptr es:[0]
mov xhole,dl
	inc byte ptr es:[1]
	mov dl,byte ptr es:[1]
mov yhole,dl
.endif
 .if(movement==6)
	dec byte ptr es:[0]
		mov dl,byte ptr es:[0]
mov xhole,dl
.endif
 .if(movement==7)
	dec byte ptr es:[0]
	 mov dl,byte ptr es:[0]
 mov xhole,dl
	 dec byte ptr es:[1]
	 mov dl,byte ptr es:[1]
mov yhole,dl
	.endif
	 .if( sbyte ptr xhole < 0 )
	mov xhole, 0
	 .elseif( sbyte ptr xhole > 79 )
	mov xhole, 79
	 .endif
	 .if( sbyte ptr yhole < 0 )
	mov yhole, 0
	 .elseif( sbyte ptr yhole > 24 )
	mov yhole, 24
	 .endif
	 mov al, xhole
	 mov es:[0], al
	 mov al, yhole
	 mov es:[1], al
	 mov si, farm
	 movzx ax,xhole
 mov dx,16
 mul dx
 mov di,ax;;;;;;;;check the answer
 movzx ax,yhole
 mov dx,80
 mul dx
; mov di,ax
mov dx,16
mul dx
	mov bx,ax
		add bx,2
		 mov cx,di
	 add bx,cx
 add word ptr [si][bx],1 ;increament in home cell
ret
 walkant endp
 ;;;;;Create and add ant;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	 addant proc near C uses si di,
	 farm:word
 ; mov ax , farm
; mov sPfirstant,ax
 @GetBlock 1
	mov es,ax
	mov di,12
mov si,farm
	mov es:[di],si
mov spfirstant,ax;move the first ant offset in spfirstant
	ret
	 addant endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;Show The Random walk and go back home;;;;;;;;;;;;;;;;
 show2 proc near c uses si di,
farm:word
 mov number,0
 mov cx,2000;go throw hole farm
 mov si,0
 mov bx,0
 mov ax,0 ;row
 mov dx,0 ;colum
 mov count,0
mov si, farm
 l1:
;;;;;;;;Get the value in ants and show its position;;;;;;;;
inc count
mov dl, [si+bx] ; get x coord
inc bx
mov dh, [si+bx] ; get y coord
 mov di,bx
 push cx
 Invoke SetPosition, dl,dh; set cursor position here
 mov bx,di
add bx,1
mov dx, [si+bx] ; get ant count
mov di, bx
; dl has color, mod with 15
.if(dx > 0)
and dx,15
 add dl,1
	inc	number
	mov num,dl
 invoke ColorChar,219d,num ;put color and attribute
.else
 invoke ColorChar,219d,0 ;put color and attribute
.endif
pop cx
mov bx,di
add bx,14
cmp count,80
jae colum
 l3:
loop l1
 jmp l2
	colum:
inc al
mov dl,0
	mov count,0
jmp l3
l2:
ret
Show2 endp
 end
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.