Go: package main

import (
	"bufio"
	"encoding/json"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

type Color int

const (
	ColorBlack Color = iota
	ColorRed
)

var strByColor = map[Color]string{
	ColorBlack: "black",
	ColorRed:   "red",
}

func (c Color) String() string {
	return strByColor[c]
}

type Node struct {
	ID      int
	X, Y    int
	Color   Color
	NextIDs map[int]struct{}
}

func (n *Node) String() string {
	d, _ := json.Marshal(n)
	return string(d)
}

type Map struct {
	Width, Height int
	Nodes         map[int]*Node
}

func (m *Map) GetByID(id int) *Node {
	return m.Nodes[id]
}

func (m *Map) Get(x, y int) *Node {
	return m.Nodes[m.getID(x, y)]
}

func (m *Map) SetColor(x, y int, c Color) {
	m.Nodes[m.getID(x, y)].Color = c
}

func (m *Map) getID(x, y int) int {
	return x + y*m.Width
}

func (m *Map) init() {
	for x := 1; x <= m.Width; x++ {
		for y := 1; y <= m.Height; y++ {
			id := m.getID(x, y)
			m.Nodes[id] = &Node{ID: id, X: x, Y: y}
		}
	}
	for x := 1; x <= m.Width; x++ {
		for y := 1; y <= m.Height; y++ {
			nextIDs := map[int]struct{}{}
			if x > 1 {
				nextIDs[m.getID(x-1, y)] = struct{}{}
			}
			if x < m.Width {
				nextIDs[m.getID(x+1, y)] = struct{}{}
			}
			if y > 1 {
				nextIDs[m.getID(x, y-1)] = struct{}{}
			}
			if y < m.Height {
				nextIDs[m.getID(x, y+1)] = struct{}{}
			}
			m.Get(x, y).NextIDs = nextIDs
		}
	}
}

func NewMap(w, h int) *Map {
	m := &Map{Width: w, Height: h, Nodes: map[int]*Node{}}
	m.init()
	return m
}

type Searcher struct {
	Map        *Map
	queue      []*Node
	touchedIDs map[int]struct{}
	visitedIDs map[int]struct{}
}

func NewSearcher(m *Map) *Searcher {
	return &Searcher{
		Map:        m,
		queue:      []*Node{},
		touchedIDs: map[int]struct{}{},
		visitedIDs: map[int]struct{}{},
	}
}

func (s *Searcher) Search(start *Node) {
	s.enqueue(start)

	for {
		if len(s.queue) == 0 {
			break
		}
		for nextID := range s.dequeue().NextIDs {
			n := s.Map.GetByID(nextID)
			if n.Color == ColorRed || s.hasTouched(n) {
				continue
			}
			s.enqueue(n)
		}
	}
}

func (s *Searcher) VisitedNodeCount() int {
	return len(s.visitedIDs)
}

func (s *Searcher) hasTouched(n *Node) bool {
	_, ok := s.touchedIDs[n.ID]
	return ok
}

func (s *Searcher) enqueue(n *Node) {
	s.queue = append(s.queue, n)
	s.touchedIDs[n.ID] = struct{}{}
}

func (s *Searcher) dequeue() *Node {
	n := s.queue[0]
	s.queue = s.queue[1:]
	s.visitedIDs[n.ID] = struct{}{}
	return n
}

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		w, _ := strconv.Atoi(chunks[0])
		h, _ := strconv.Atoi(chunks[1])

		m := NewMap(w, h)

		// Set colors
		var start *Node
		for y := 1; y <= h; y++ {
			sc.Scan()
			for i, c := range sc.Text() {
				switch c {
				case '.', '@':
					m.SetColor(i+1, y, ColorBlack)
					if c == '@' {
						start = m.Get(i+1, y)
					}
				case '#':
					m.SetColor(i+1, y, ColorRed)
				}
			}
		}

		// Search
		s := NewSearcher(m)
		s.Search(start)
		fmt.Println(s.VisitedNodeCount())
	}
}

Python: #!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
import itertools
import sys


UNDET_POINT = (-1, -1)


class RecursiveDepthFirstSearch(object):

    def __init__(self, width, height, tiles):
        self.width = width
        self.height = height
        self.tiles = tiles
        self.reached = [array.array(
            "B", (False for j in range(height))) for i in range(width)]
        self.start_tile = UNDET_POINT
        for x, y in itertools.product(range(width), range(height)):
            if tiles[x][y] == "@":
                self.start_tile = (x, y)
                break

    def search(self, x, y):
        if x < 0 or self.width <= x or y < 0 or self.height <= y:
            pass
        elif self.tiles[x][y] == "#":
            pass
        elif self.reached[x][y]:
            pass
        else:
            self.reached[x][y] = True
            self.search(x + 1, y)
            self.search(x - 1, y)
            self.search(x, y + 1)
            self.search(x, y - 1)

    def count_reachable_tiles(self):
        self.search(*self.start_tile)
        reachable_tiles = sum([self.reached[x][y] for x, y in itertools.product(
            range(self.width), range(self.height))])
        return reachable_tiles


if __name__ == "__main__":
    sys.setrecursionlimit(10000)
    while True:
        width, height = map(int, input().split())
        if width == 0 and height == 0:
            break
        else:
            tiles = [x for x in zip(*[input() for y in range(height)])]
            dfs = RecursiveDepthFirstSearch(width, height, tiles)
            print(dfs.count_reachable_tiles())

Python: class dfs:
    def __init__(self,W,H,m):
        self.W=W
        self.H=H
        self.m=m
        self.ans=0
        self.visited=[[False]*W for _ in range(H)]
    def trav(self,x,y):
        #print(x,y)
        self.visited[x][y]=True
        self.ans+=1
        offset=[(-1,0),(0,-1),(1,0),(0,1)]
        for dx,dy in offset:
            x2=x+dx
            y2=y+dy
            if 0<=x2<self.H and 0<=y2<self.W and self.m[x2][y2]=='.' and self.visited[x2][y2]==False:
                self.trav(x2,y2)
    

while True:
    W,H=map(int,input().split())
    if not (W and H): break
    m=[]
    for i in range(H):
        L=list(input())
        if '@' in L:
            (sx,sy)=(i,L.index('@'))
        m.append(L)
    D=dfs(W,H,m)
    D.trav(sx,sy)
    print(D.ans)

Python: def dfs(tiles, w, h, x, y):
    cnt = 1
    tiles[y][x] = '@'
    for dx,dy in ((0,1), (0,-1), (-1,0), (1,0)):
        if 0<=x+dx<w and 0<=y+dy<h and tiles[y+dy][x+dx]=='.':
            cnt += dfs(tiles, w, h, x+dx, y+dy)
    return cnt

def main():
    while True:
        W,H = [int(x) for x in input().split()]
        if W==0 and H==0:
            exit()
        tiles = [[c for c in input()] for h in range(H)]
        for i in range(H):
            if '@' in tiles[i]:
                Y = i
                X = tiles[i].index('@')
        answer = dfs(tiles, W, H, X, Y)
        print(answer)

if __name__ == '__main__':
    main()

Python: import math

def search(w,h,data): 
    for i in range(h):
        if '@' in data[i]:
            stx,sty = i,data[i].index('@')

    stack = [[stx,sty]]
    check = [[stx,sty]]
    while True:
        if len(stack) != 0:
            s = stack[-1]
            Hnow,Wnow = s[0],s[1]
        else:
            return len(check)

        stack.pop()
        
        if Hnow < h-1:
            if (data[Hnow+1][Wnow] == '.') and ([Hnow+1,Wnow] not in check):
                stack.append([Hnow+1,Wnow])
                check.append([Hnow+1,Wnow])

        if Wnow < w-1:
            if (data[Hnow][Wnow+1] == '.') and ([Hnow,Wnow+1] not in check):
                stack.append([Hnow,Wnow+1])
                check.append([Hnow,Wnow+1])

        if Hnow > 0:
            if (data[Hnow-1][Wnow] == '.') and ([Hnow-1,Wnow] not in check):
                stack.append([Hnow-1,Wnow])
                check.append([Hnow-1,Wnow])

        if Wnow > 0:
            if (data[Hnow][Wnow-1] == '.') and ([Hnow,Wnow-1] not in check):
                stack.append([Hnow,Wnow-1])
                check.append([Hnow,Wnow-1])

a = []


while True:
    w,h = list(map(int,input().split()))
    if (w == 0)and(h == 0):
        break
    else:
        data = [list(input()) for l in range(h)]
        a.append(search(w,h,data))

for i in a:
    print(i)